mirror of
https://github.com/vbatts/tar-split.git
synced 2024-11-18 06:18:37 +00:00
main.go: collect more end padding
This commit is contained in:
parent
9d24762ee1
commit
d96a87d9a2
1 changed files with 12 additions and 2 deletions
14
main.go
14
main.go
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue