mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
lib/suitar: add trailing EOF blocks
Both /usr/bin/tar and the Go standard library don't seem to need this, but some other TAR readers might expect it.
This commit is contained in:
1 parent
504f8485f4
commit
0f214ba59c
4 files changed
+24
-6
No files matched your search
@@ -30,8 +30,7 @@ BZIP2", etc. A separate compression step wrapping SUITAR is feasible, just like
|
||||
wrapping TAR, but is out of scope of this document.
|
||||
|
||||
Like TAR, SUITAR files are a sequence of independent entries (files or
|
||||
directories). Independent means that the concatenation of two valid SUITAR
|
||||
files is itself a valid SUITAR file. Like JSON map keys, duplicate names are
|
||||
directories). Independent means that, like JSON map keys, duplicate names are
|
||||
valid, although some decoders may choose to reject them.
|
||||
|
||||
A file's entry does not need to be preceded by explicit entries for that file's
|
||||
@@ -97,8 +96,9 @@ and transform Shift-JIS encoded names to equivalent and valid UTF-8.
|
||||
|
||||
## File Structure
|
||||
|
||||
SUITAR files are a sequence of independent entries and each entry occupies an
|
||||
integer number of 512-byte blocks:
|
||||
SUITAR files are a sequence of entries, followed by a 1024-byte "End Of File"
|
||||
marker. The EOF marker's bytes are all NUL. Each entry occupies an integer
|
||||
number of 512-byte blocks:
|
||||
|
||||
- 1 `GNUTYPE_LONGNAME` header block.
|
||||
- 1 or more payload blocks containing the file or directory name.
|
||||
|
||||
+20
-2
@@ -471,6 +471,11 @@ func (w *Writer) Close() error {
|
||||
if err := w.flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
clear(w.nameBuf[:1024])
|
||||
if _, err := w.w.Write(w.nameBuf[:1024]); err != nil {
|
||||
w.err = err
|
||||
return err
|
||||
}
|
||||
w.err = errClosed
|
||||
return nil
|
||||
}
|
||||
@@ -503,9 +508,23 @@ func (r *Reader) Next() (Header, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(r.r, r.block[:]); err != nil {
|
||||
if _, err := readFullNoEOF(r.r, r.block[:]); err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
} else if r.block[0x09C] == 0 {
|
||||
// SUITAR ends with 2 blocks (1024 bytes) of zeroes.
|
||||
if !isAllZeroes(r.block[:]) {
|
||||
r.err = errBadHeader
|
||||
return Header{}, r.err
|
||||
} else if _, err := readFullNoEOF(r.r, r.block[:]); err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
} else if !isAllZeroes(r.block[:]) {
|
||||
r.err = errBadHeader
|
||||
return Header{}, r.err
|
||||
}
|
||||
r.err = io.EOF
|
||||
return Header{}, r.err
|
||||
}
|
||||
|
||||
nameLenInclNul, err := parseBlock0(&r.block)
|
||||
@@ -545,7 +564,6 @@ func (r *Reader) Next() (Header, error) {
|
||||
Mode: mode,
|
||||
ModTime: time.Unix(modTime, 0),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func parseBlock0(b *block) (uint64, error) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user