[Archive]TarWriterThe streaming writer, from [Archive]Tar.writeTo:. Members are written in call order as POSIX ustar; a name longer than 100 bytes gets a pax path= extended header (what the reader above and every system tar understand). Defaults are deliberate: mode 0644 (dirs 0755), uid/gid 0, mtime now (addFile:as: keeps the source file's). close writes the two zero end blocks and closes the stream — through the codec when it is gzip-wrapped, so .tar.gz needs no extra step. Close deliberately; an unclosed archive is missing its end marker.
var tar = [Archive]Tar.writeTo:(([IO]File.create:'backup.tar.gz').gzip) tar.add:'notes/today.txt' text:'ship the writer' tar.addFile:'/var/log/build.log' as:'logs/build.log' tar.close
Add one file member with the given content (bytes or, via add:text:, a UTF-8 String). Answers self.
add:bytes: for text: the content is the String's UTF-8 bytes.
Add a file from disk under the archive name name, streamed in chunks — the content never materializes whole. Size and mtime come from the file's metadata snapshot; a file that proves shorter than its snapshot throws. Answers self.
Add a directory member (a trailing '/' is added if missing). Answers self.
Sum the header with the checksum field as spaces, then write the sum as six octal digits, NUL, space — the traditional encoding.
End the archive: the two 512-byte zero end blocks, then close the stream (finishing a gzip wrap — the whole .tar.gz becomes valid here). Idempotent. Returns nil.
Write one 512-byte ustar header; a name over 100 bytes is carried in a pax path= extended header first, with the ustar field truncated.
Internal.
Pad the last content block out to 512 bytes.
The pax extended header ('x') whose one record overrides the next member's path: '<len> path=<value>\n', len counting the whole record.
A right-aligned, zero-padded, NUL-terminated octal field.
Copy bytes into the header list at at.