std/archive
On this page
Index
- type
Entry - type
ArchiveErr- method
ArchiveErr.display
- method
- type
ZipFile - type
ZipReader- method
ZipReader.files - method
ZipReader.read
- method
- type
ZipWriter- method
ZipWriter.add - method
ZipWriter.create - method
ZipWriter.write - method
ZipWriter.close
- method
- fn
file - fn
dir - fn
gzip - fn
gunzip - fn
tar - fn
untar - fn
zip - fn
unzip - fn
zip_reader - fn
zip_open - fn
zip_writer
Types
Entry
struct Entry {
path: Str
data: Bytes
mode: Int
is_dir: Bool
modified: Time
}A file or directory of an archive. path uses /; a directory’s
data is empty (unzip and untar of an entry whose mode says directory
return no data for it, even when the archive stores some, decision 0164).
ArchiveErr
struct ArchiveErr {
msg: Str
}Displays as archive: ....
ArchiveErr.display
fn (e: ArchiveErr) display() -> StrZipFile
struct ZipFile {
path: Str
size: Int
compressed: Int
mode: Int
is_dir: Bool
modified: Time
offset: Int
method: Int
flags: Int
crc: Int
}One entry of a zip archive’s central directory (decision 0479):
size is the inflated length and compressed the stored one. The
fields after modified are the header’s own, for ZipReader.read.
ZipReader
struct ZipReader {
data: Bytes
list: List[ZipFile]
file: File?
total: Int
}A zip archive (in memory, or in a File) whose central directory was
read once and whose entries are inflated one at a time. @internal: use zip_reader,
r.files() and r.read(f)
ZipReader.files
fn (r: ZipReader) files() -> List[ZipFile]The entries in directory order.
ZipReader.read
fn (r: ZipReader) read(f: ZipFile) -> Bytes ! ArchiveErr uses fs.readOne entry’s contents, inflated and checked against its CRC; a directory’s is empty.
ZipWriter
struct ZipWriter {}A zip archive written entry by entry to a File (decision 0479): memory
is the directory records, not the data. The File stays the caller’s:
open it for writing, and close it after close. Entries are deflated;
an archive past 65,535 entries or 4 GiB is an error (no zip64).
@move_only
ZipWriter.add
fn (var w: ZipWriter) add(e: Entry) -> () ! ArchiveErr uses fs.writeWrites an entry whose data is in hand, ending the entry before it.
ZipWriter.create
fn (var w: ZipWriter) create(path: Str, mode: Int = 0o644) -> () ! ArchiveErr uses fs.writeStarts a streamed file entry (its time the Unix epoch, as file),
ending the one before it; write gives it data.
ZipWriter.write
fn (var w: ZipWriter) write(data: Bytes) -> () ! ArchiveErr uses fs.writeData for the entry create started (a data descriptor follows it).
ZipWriter.close
fn (var w: ZipWriter) close() -> () ! ArchiveErr uses fs.writeEnds the last entry and writes the central directory. @moves
Functions
file
fn file(path: Str, data: Bytes) -> EntryA file entry with mode 0o644 and the Unix epoch as its time.
dir
fn dir(path: Str) -> EntryA directory entry with mode 0o755.
gzip
fn gzip(data: Bytes) -> Bytesdata compressed in the gzip format (RFC 1952), at the default level.
gunzip
fn gunzip(data: Bytes) -> Bytes ! ArchiveErrtar
fn tar(entries: List[Entry]) -> Bytes ! ArchiveErrA tar archive (POSIX ustar or PAX) of the entries, in order.
untar
fn untar(data: Bytes) -> List[Entry] ! ArchiveErrThe entries of a tar archive. An entry whose path is absolute or
leaves the archive’s root (..) is an error, as are links and devices.
zip
fn zip(entries: List[Entry]) -> Bytes ! ArchiveErrA zip archive of the entries (deflated), in order.
unzip
fn unzip(data: Bytes) -> List[Entry] ! ArchiveErrThe entries of a zip archive, with the same path rules as untar.
zip_reader
fn zip_reader(data: Bytes) -> ZipReader ! ArchiveErrThe archive’s directory, checked as unzip checks it (paths, kinds,
Go’s errors); no entry is inflated.
zip_open
fn zip_open(f: File, size: Int) -> ZipReader ! ArchiveErr uses fs.readA zip archive of size bytes in a File (Fs.stat gives the size), read
in place: the tail and the central directory are read now and an
entry’s bytes when read asks, so an archive larger than memory can be
walked. The File stays the caller’s and must stay open and unchanged.
zip_writer
fn zip_writer(f: File) -> ZipWriter