Skip to content

Instantly share code, notes, and snippets.

@aki237
Created April 14, 2017 07:53
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 aki237/fb0507b51e3f1bea41c5a06e1ec3dcc9 to your computer and use it in GitHub Desktop.
Save aki237/fb0507b51e3f1bea41c5a06e1ec3dcc9 to your computer and use it in GitHub Desktop.
func addParts(filename string, files []string) {
// filename : filename of full file.
// files : array of filenames of parts.
// Create if not found and open mode as append..
// So writing means adding.
out, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
// usual.
check err
// loop through `files` and write (add) it to the resulting file.
for _, val := range files {
f, err := os.Open(val)
check err
_, err = io.Copy(out, f)
check err
f.Close()
// Remove the temp file too...
os.Remove(val)
}
// Close the output file.
out.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment