split_csv

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 8 Imported by: 1

README

Vue logo

Split csv

GoDoc Go Report Card codecov FOSSA Status License

Fast and efficient Golang package for splitting large csv files on smaller chunks by size in bytes.

Features:

  • Super-fast splitting. Splitting of 700MB+ file takes less than 1 sec!
  • Allocates minimum memory regardless file size.
  • Supports multiline cells and headers (csv should follow the basic rules https://en.wikipedia.org/wiki/Comma-separated_values).
  • Configurable destination folder.
  • Disabling/enabling of copying a header in chunk files.

Installation

Install:

go get -u github.com/tolik505/split-csv

Import:

import splitCsv "github.com/tolik505/split-csv"

Quickstart

func ExampleSplitCsv() {
	splitter := splitCsv.New()
	splitter.Separator = ";"     // "," is by default
	splitter.FileChunkSize = 100000000 //in bytes (100MB)
	result, _ := splitter.Split("testdata/test.csv", "testdata/")
	fmt.Println(result)
	// Output: [testdata/test_1.csv testdata/test_2.csv testdata/test_3.csv]
}

If copying of a header in chunks is not needed then:

func ExampleSplitCsv() {
	splitter := splitCsv.New()
	splitter.Separator = ";"     // "," is by default
	splitter.FileChunkSize = 20000000 //in bytes (20MB)
	s.WithHeader = false //copying of header in chunks is disabled
	result, _ := splitter.Split("testdata/test.csv", "testdata/")
	fmt.Println(result)
	// Output: [testdata/test_1.csv testdata/test_2.csv testdata/test_3.csv]
}

License

FOSSA Status

Documentation

Overview

Package split_csv implements splitting of csv files on chunks by size in bytes

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongSeparator     = errors.New("only one-byte separators are supported")
	ErrSmallFileChunkSize = errors.New("file chunk size is too small")
	ErrBigFileChunkSize   = errors.New("file chunk size is bigger than input file")
)

Functions

This section is empty.

Types

type Splitter

type Splitter struct {
	FileChunkSize int //in bytes
	WithHeader    bool
	Separator     string
	// contains filtered or unexported fields
}

Splitter struct which contains options for splitting FileChunkSize - a size of chunk in bytes, should be set by client WithHeader - whether split csv with header (true by default)

func New

func New() Splitter

New initializes Splitter struct

func (Splitter) Split

func (s Splitter) Split(inputFilePath string, outputDirPath string) ([]string, error)

Split splits file in smaller chunks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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