Skip to content

Instantly share code, notes, and snippets.

@callumj
Last active August 29, 2015 13:59
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 callumj/10573518 to your computer and use it in GitHub Desktop.
Save callumj/10573518 to your computer and use it in GitHub Desktop.
Merge
func mergeIntoBaseArchive(baseArchive ArchiveInfo, basedir string, contents []string, file string) {
var mapped map[string]bool
mapped = make(map[string]bool)
for _, item := range contents {
stripped := strings.Replace(item, basedir, "", 1)
mapped[stripped] = true
}
// tar pntr for copy
dupe, dupeErr := os.Create(file)
if (dupeErr != nil) {
panic(dupeErr)
}
basePntr, baseErr := os.Open(baseArchive.Path)
if (baseErr != nil) {
panic(baseErr)
}
for _, item := range baseArchive.Items {
_, posErr := basePntr.Seek(item.Start, 0)
if (posErr != nil) {
log.Fatalln(posErr)
}
io.CopyN(dupe, basePntr, item.Length)
}
basePntr.Close()
dupe.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment