Last active
August 29, 2015 13:59
-
-
Save callumj/10573518 to your computer and use it in GitHub Desktop.
Merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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