Skip to content

MultiCSV is a multi reader that's the logical concatenation of the provided input csv readers

License

Notifications You must be signed in to change notification settings

zero-pkg/multicsv

Repository files navigation

multicsv

build Go Report Card MIT License

MultiCSV is a multi reader that's the logical concatenation of the provided input csv readers. They're read sequentially. Once all inputs have returned EOF, Read will return EOF. If any of the readers return a non-nil, non-EOF error, Read will return that error.

Install and update

go get -u github.com/zero-pkg/multicsv

How to use

r := multicsv.NewReader(
    multicsv.LazyFileReader("data/users.csv", true),
    multicsv.LazyFileReader("data/users2.csv", true),
)

records, err := r.ReadAll()
if err != nil {
    panic(err)
}

fmt.Println(records)

Extending LazyReader

func main() {
	r := multicsv.NewReader(
		customReader("data/count_10.csv"),
		customReader("data/count_100.csv"),
	)
}

func customReader(file string) *multicsv.LazyReader {
	return &multicsv.LazyReader{
		Init: func() (*csv.Reader, error) {
			f, err := os.Open(file)
			if err != nil {
				return nil, err
			}

			// customize csv.Reader
			r := csv.NewReader(f)
			r.LazyQuotes = true

			return r, nil
		},
	}
}

License

http://www.opensource.org/licenses/mit-license.php

About

MultiCSV is a multi reader that's the logical concatenation of the provided input csv readers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages