macreader

package module
v0.0.0-...-d4ef811 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2015 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package macreader changes Classic Mac (CR) line endings to Linux (LF) line endings in files. This is useful when handling CSV files generated by the Mac version of Microsoft Excel as documented in this issue: https://github.com/golang/go/issues/7802.

Example
// testFile is a CSV file with CR line endings.
testFile := bytes.NewBufferString("a,b,c\r1,2,3\r").Bytes()

// First try reading the csv file the normal way.
// The CSV reader doesn't recognize the '\r' line ending.
r1 := csv.NewReader(bytes.NewReader(testFile))
lines1, err := r1.ReadAll()
if err != nil {
	fmt.Println(err)
}
fmt.Printf("Without macreader: %#v\n", lines1)

// Now try reading the csv file using macreader.
// It should work as expected.
r2 := csv.NewReader(New(bytes.NewReader(testFile)))
lines2, err := r2.ReadAll()
if err != nil {
	fmt.Println(err)
}
fmt.Printf("With macreader: %#v\n", lines2)
Output:

Without macreader: [][]string{[]string{"a", "b", "c\r1", "2", "3"}}
With macreader: [][]string{[]string{"a", "b", "c"}, []string{"1", "2", "3"}}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(r io.Reader) io.Reader

New creates a new io.Reader that wraps r to convert Classic Mac (CR) line endings to Linux (LF) line endings.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL