1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2024-11-22 16:15:39 +00:00

main.go: collect more end padding

This commit is contained in:
Vincent Batts 2015-02-20 15:28:48 -05:00
parent 9d24762ee1
commit d96a87d9a2

14
main.go
View file

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
@ -18,7 +19,7 @@ func main() {
// Open the tar archive
fh, err := os.Open(arg)
if err != nil {
log.Fatal(err)
log.Fatal(err, arg)
}
defer fh.Close()
@ -31,7 +32,7 @@ func main() {
fi, err := fh.Stat()
if err != nil {
log.Fatal(err)
log.Fatal(err, fh.Name())
}
size := fi.Size()
var sum int64
@ -69,6 +70,15 @@ func main() {
fmt.Println(hdr.Name, "pre:", len(pre), "read:", i, "post:", len(post))
}
// it is allowable, and not uncommon that there is further padding on the
// end of an archive, apart from the expected 1024 null bytes
remainder, err := ioutil.ReadAll(fh)
if err != nil && err != io.EOF {
log.Fatal(err, fh.Name())
}
output.Write(remainder)
sum += int64(len(remainder))
if size != sum {
fmt.Printf("Size: %d; Sum: %d; Diff: %d\n", size, sum, size-sum)
fmt.Printf("Compare like `cmp -bl %s %s | less`\n", fh.Name(), output.Name())