Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created October 3, 2014 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/20f514df7a0dbad0be5f to your computer and use it in GitHub Desktop.
Save harshavardhana/20f514df7a0dbad0be5f to your computer and use it in GitHub Desktop.
Split files
package main
import (
"flag"
"fmt"
"io/ioutil"
)
const (
SPLIT_NFILES = 4
)
func main() {
var filename, newfile string
var readBytes, splitBytes []byte
var err error
flag.StringVar(&filename, "file", "testfile", "[FILENAME]")
flag.Parse()
readBytes, err = ioutil.ReadFile(filename)
if err != nil {
return
}
splitn := len(readBytes) / SPLIT_NFILES
splitBytes = readBytes[:splitn]
newfile = filename + "1"
if splitBytes != nil {
ioutil.WriteFile(newfile, splitBytes, 0777)
fmt.Println("Written +", splitn)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment