Skip to content

A small Go utility for splitting a file into smaller ones.

License

Notifications You must be signed in to change notification settings

knwoop/splitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

splitter

A small Go utility for splitting a file into smaller ones.

Installation

$ go get -u github.com/knwoop/splitter

sample cmd

$ splitter -path _example/example.csv -sep 3 -head 

how to use

package main

import (
    "fmt"
    "log"
    "os"
    
    "github.com/knwoop/splitter"
)

func main() {
    f, err := os.Open("test.csv")
    if err != nil{
        log.Fatal(err)
    }
    defer f.Close() 
    readers, err := splitter.Split(f, true, 40)
    if err != nil {
        log.Fatal(err)
    }
    ...
}

Let's playground

package main

import (
	"bytes"
	"fmt"
	"log"
	"strings"

	"github.com/knwoop/splitter"
)

var csv = `header1,header2
"1111","22222"
33333,44444
55555,66666
77777,88888`

func main() {
	r := strings.NewReader(csv)
	readers, err := splitter.Split(r, true, 3)
	if err != nil {
		log.Fatal(err)
	}
	buf1 := new(bytes.Buffer)
	if _, err := buf1.ReadFrom(readers[0]); err != nil {
		log.Fatal(err)
	}
	buf2 := new(bytes.Buffer)
	if _, err := buf2.ReadFrom(readers[1]); err != nil {
		log.Fatal(err)
	}
	fmt.Println(buf1)
	fmt.Println(buf2)
}

About

A small Go utility for splitting a file into smaller ones.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages