format::tar
This module provides an implementation of the tar archive format for Unix. The specific format implemented is USTAR, however, it is capable of reading most tar variants which are backwards-compatible with the original format (e.g. GNU tar).
To read an archive, use read to create a reader, and next to enumerate its entries. The return value from next contains the file metadata and is an io::stream that you may read the file contents from. You may call skip to skip an archive entry without reading it.
Index
Types
type entry = struct {
ent_reader,
name: str,
mode: uint,
uid: uint,
gid: uint,
fsize: size,
mtime: uint,
checksum: uint,
etype: entry_type,
link: str,
uname: str,
gname: str,
devmajor: u64,
devminor: u64,
};
type entry_type = enum u8 {
FILE,
HARDLINK,
SYMLINK,
CHARDEV,
BLOCKDEV,
DIRECTORY,
FIFO,
};
type ent_reader = struct {
vtable: io::stream,
src: io::handle,
orig: size,
remain: size,
};
type reader = struct {
src: io::handle,
name: [255]u8,
};
Errors
type error = !(invalid | io::error);
type invalid = !void;
Constants
def BLOCKSZ: size = 512;
Functions
fn next(rd: *reader) (entry | error | io::EOF);
fn read(src: io::handle) reader;
fn skip(ent: *entry) (void | io::error);
fn strerror(err: error) const str;
Types
type entry
type entry = struct {
ent_reader,
name: str,
mode: uint,
uid: uint,
gid: uint,
fsize: size,
mtime: uint,
checksum: uint,
etype: entry_type,
link: str,
uname: str,
gname: str,
devmajor: u64,
devminor: u64,
};
A file or directory in a tar file.
type entry_type
type entry_type = enum u8 {
FILE,
HARDLINK,
SYMLINK,
CHARDEV,
BLOCKDEV,
DIRECTORY,
FIFO,
};
A tar file entry. Note that some systems create tarballs with additional vendor-specific values for the entry type, so a default case is recommended when switching against this.
type ent_reader
Show undocumented member
type ent_reader = struct {
vtable: io::stream,
src: io::handle,
orig: size,
remain: size,
};
type reader
Show undocumented member
type reader = struct {
src: io::handle,
name: [255]u8,
};
Errors
type error
type error = !(invalid | io::error);
Tagged union of all possible error types.
type invalid
type invalid = !void;
Returned if the source file does not contain a valid ustar archive.
Constants
def BLOCKSZ
def BLOCKSZ: size = 512;
The size of each block in a tar file.
Functions
fn next
fn next(rd: *reader) (entry | error | io::EOF);
Returns the next entry from a tar reader. Parts of this structure (specifically the file name) are borrowed from the reader itself and will not be valid after subsequent calls.
If the return value is a file (i.e. entry.etype == entry_type::FILE), the caller must either call io::read using the return value until it returns io::EOF, or call skip to seek to the next entry in the archive.
Note that reading from the header will modify the file size.
fn read
fn read(src: io::handle) reader;
Creates a new reader for a tar file. Use next to iterate through entries present in the tar file.
fn skip
fn skip(ent: *entry) (void | io::error);
Seeks the underlying tar file to the entry following this one.
fn strerror
fn strerror(err: error) const str;
Converts an error to a human-friendly representation.