package core:archive

⌘K
Ctrl+K
or
/

    Overview

    Reads archives of any registered format through one API, and extracts them safely.

    Each format is its own package, core:archive/zip, core:archive/sevenz or core:archive/tar, and registers itself here when imported. Writing and format-specific details go through those packages.

    Reading:

    • open detects the format and opens an archive from a path, a byte slice or a seekable io.Stream, self-extracting zip and 7z archives included
    • iterator_create and iterate list members in storage order; find looks one up by path
    • Members are extracted to an io.Writer or streamed through an io.Reader
    • File_Info describes a member the same way in every format

    Extracting:

    • extract_all and extract_current_to_dir write members below a directory; paths that escape it or cross a symlink are refused
    • extract_many extracts members chosen by path to files, buffers or writers, in one pass
    • Extract_Options caps the total size and the compression ratio
    • On js only byte slices and streams are supported; the path procs are left out

    Packages 3

    sevenzReads, writes and updates 7z archives, as described by DOC/7zFormat.txt in Igor Pavlov's
    tarReads and writes tar archives: v7, ustar and pax as specified by POSIX.1-2024, and GNU tar's.
    zipReads, writes and updates ZIP archives, as specified by version 6.3.10 (November 2022) of

    Types

    Archive ¶

    Archive :: struct {
    	format:    Format,
    	state:     rawptr,
    	file:      io.Stream,
    	// The file `open_from_path` opened as a stream; `close` closes it
    	allocator: runtime.Allocator,
    }
     

    An archive of any registered format, from open

    Related Procedures With Parameters

    Related Procedures With Returns

    Archive_Info ¶

    Archive_Info :: struct {
    	format:       Format,
    	member_count: int,
    	// -1 for tar until the end has been read
    	comment:      string,
    	// The archive comment (zip) or volume label (tar)
    	compression:  Method,
    }
     

    An archive's summary, from info

    Disk ¶

    Disk :: struct {
    	target:       ^os.File,
    	temp:         ^os.File,
    	path:         string,
    	temp_path:    string,
    	journal_path: string,
    	allocator:    runtime.Allocator,
    	no_sync:      bool,
    }

    Entry_Type ¶

    Entry_Type :: enum u8 {
    	Unknown,          // A type this package doesn't know
    	Regular, 
    	Directory, 
    	Symlink, 
    	Hard_Link, 
    	Named_Pipe, 
    	Character_Device, 
    	Block_Device, 
    	Anti,             // A 7z anti-item: marks the path as deleted
    }
     

    What kind of file system object a member is

    Extract_Iterator ¶

    Extract_Iterator :: struct {
    	archive:   ^Archive,
    	it:        Iterator,
    	targets:   []Target,
    	options:   Extract_Options,
    	found:     int,
    	total:     i64,
    	done:      bool,
    	err:       Error,
    	err_path:  [dynamic]u8,
    	last_err:  Error,
    	last_path: [dynamic]u8,
    	allocator: runtime.Allocator,
    }
     

    Extracts targets in one pass over an archive, from extract_iterator_create

    Related Procedures With Parameters

    Extract_Options ¶

    Extract_Options :: struct {
    	overwrite:      bool,
    	// Replace existing files
    	last_wins:      bool,
    	// Extract every member with a target's path, so the last one wins
    	max_total_size: i64,
    	// The most bytes to extract in all, 0 for no limit
    	max_ratio:      int,
    	// The most a member may expand over its compressed size, 0 for no limit
    	password:       string,
    }
     

    How to extract members

    Related Procedures With Parameters

    Extractor ¶

    Extractor :: struct {
    	options:   Extract_Options,
    	path:      [dynamic]u8,
    	root:      int,
    	total:     i64,
    	checked:   [dynamic]u8,
    	allocator: runtime.Allocator,
    }
     

    Extracts members into a directory, from extractor_create

    Related Procedures With Parameters

    File_Info ¶

    File_Info :: struct {
    	path:              string,
    	// In UTF-8, without a leading `./` or trailing `/`
    	raw_path:          []u8,
    	// The path's bytes as stored, e.g. zip's CP437 or 7z's UTF-16
    	link_target:       string,
    	// Set by tar; `read_link` reads a link's target in any format
    	comment:           string,
    	// The member's comment (zip)
    	type:              Entry_Type,
    	size:              i64,
    	// Uncompressed size; writers take -1 for a reader of unknown size
    	compressed_size:   i64,
    	// Stored size, -1 if unknown: compressed tar, solid 7z
    	method:            Method,
    	method_id:         u64,
    	// The format's own method: zip's method number, 7z's coder ID
    	filters:           bit_set[Filter; u16],
    	// 7z filters applied before compression
    	encrypted:         bool,
    	supported:         bool,
    	// `false` if the method, encryption or entry type can't be read
    	extended_metadata: bool,
    	// Has extra fields, pax records or a comment
    	crc32:             runtime.Maybe($T=u32),
    	// The data's CRC-32, if the archive stores one
    	unix_mode:         u32,
    	// Unix type and permission bits, see `UNIX_*`
    	dos_attributes:    u32,
    	// DOS attribute bits, see `DOS_*`
    	uid:               i64,
    	gid:               i64,
    	user:              string,
    	group:             string,
    	device:            [2]u32,
    	// A device node's major and minor numbers (tar)
    	modification_time: time.Time,
    	creation_time:     time.Time,
    	// Zero if not stored
    	access_time:       time.Time,
    	// Zero if not stored
    	handle:            Handle,
    }
     

    A member's metadata, as iterate and find return it and write_entry takes it

    Related Procedures With Parameters

    Related Procedures With Returns

    Filter ¶

    Filter :: enum u8 {
    	Delta, 
    	BCJ_X86, 
    	BCJ_PPC, 
    	BCJ_IA64, 
    	BCJ_ARM, 
    	BCJ_ARMT, 
    	BCJ_SPARC, 
    	BCJ_ARM64, 
    	BCJ_RISCV, 
    	BCJ2, 
    	Swap2, 
    	Swap4, 
    }
     

    A 7z filter applied before compression: delta, a branch converter (BCJ) or a byte swap

    Filters ¶

    Filters :: bit_set[Filter; u16]
     

    The filters a member's data passes through

    Format ¶

    Format :: enum u8 {
    	Unknown, 
    	Tar, 
    	Zip, 
    	SevenZ, 
    }
     

    An archive format; which detects the registered ones

    Format_Procs ¶

    Format_Procs :: struct {
    	detect:           proc(head: []u8) -> bool,
    	open_bytes:       proc(a: ^Archive, data: []u8, options: compress.Options, read_options: Read_Options) -> Error,
    	open_stream:      proc(a: ^Archive, s: io.Stream, options: compress.Options, read_options: Read_Options) -> Error,
    	open_path:        proc(a: ^Archive, path: string, options: compress.Options, read_options: Read_Options) -> Error,
    	close:            proc(a: ^Archive),
    	info:             proc(a: ^Archive) -> Archive_Info,
    	iterator_create:  proc(it: ^Iterator) -> Error,
    	iterator_destroy: proc(it: ^Iterator),
    	iterate:          proc(it: ^Iterator) -> (fi: File_Info, index: int, ok: bool),
    	iterator_error:   proc(it: ^Iterator) -> (path: string, err: Error),
    	extract_current:  proc(it: ^Iterator, w: io.Stream, options: Read_Options) -> Error,
    	open_current:     proc(it: ^Iterator, options: Read_Options) -> (r: io.Stream, err: Error),
    	read_link:        proc(it: ^Iterator, options: Read_Options, allocator: runtime.Allocator) -> (target: string, err: Error),
    	find:             proc(a: ^Archive, path: string) -> (fi: File_Info, handle: Handle, ok: bool, err: Error),
    	extract:          proc(a: ^Archive, handle: Handle, w: io.Stream, options: Read_Options) -> Error,
    	open_member:      proc(a: ^Archive, handle: Handle, options: Read_Options) -> (r: io.Stream, err: Error),
    }

    General_Error ¶

    General_Error :: enum u32 {
    	None, 
    	Unknown_Format,        // No registered format recognizes the data
    	Not_Seekable,          // The stream can't seek or report its size
    	Unsupported_Method,    // A compression, filter or encryption method this package can't handle
    	Unsupported_Entry,     // An entry type the format or the operation can't handle
    	Encrypted,             // The member is encrypted and no password was given
    	Wrong_Password,        // The password check failed
    	Authentication_Failed, // The decrypted data failed its MAC check
    	Unsafe_Path,           // The path is absolute, uses `..`, crosses a symlink or isn't valid here
    	Not_Found,             // No member has the path, or the handle is stale
    	Exists,                // The path is already taken
    	Skipped_Entry_Type,    // Extraction skipped a member of a type it doesn't extract
    	Incompatible_Options,  // An option is out of range, or options conflict
    	No_Current_Member,     // The iterator isn't on a member
    	Limit_Exceeded,        // A size, ratio, link-target or key-derivation limit was hit
    	Busy,                  // Another process holds the archive's lock
    }
     

    Errors any format can return

    Handle ¶

    Handle :: struct {
    	index:      int,
    	generation: u32,
    }
     

    Identifies a member for extract and open_member; take it from File_Info.handle or find

    Related Procedures With Parameters

    Iterator ¶

    Iterator :: struct {
    	archive: ^Archive,
    	state:   rawptr,
    	err:     Error,
    }
     

    Walks an Archive's members, from iterator_create

    Related Procedures With Parameters

    Journal ¶

    Journal :: struct {
    	old_length:  i64,
    	check_end:   i64,
    	ranges:      [4]Journal_Range,
    	range_count: int,
    }

    Journal_Range ¶

    Journal_Range :: struct {
    	offset:   i64,
    	length:   i64,
    	crc:      u32,
    	position: i64,
    }

    Lock_Kind ¶

    Lock_Kind :: enum u8 {
    	Shared, 
    	Exclusive, 
    }

    Method ¶

    Method :: enum u16 {
    	Unknown,   // Not listed here, see `File_Info.method_id`; in writer options, the format's default
    	Store, 
    	Shrink, 
    	Reduce, 
    	Implode, 
    	Deflate, 
    	Deflate64, 
    	BZip2, 
    	LZMA, 
    	LZMA2, 
    	XZ, 
    	PPMd_H,    // PPMd variant H, as 7z uses it
    	PPMd_I,    // PPMd variant I, revision 1, as zip uses it
    	LZ4, 
    }
     

    A compression method, named the same across formats

    OS_Error ¶

    OS_Error :: os.Error
     

    The OS errors Error carries

    Range ¶

    Range :: struct {
    	offset: i64,
    	data:   []u8,
    }

    Read_Options ¶

    Read_Options :: struct {
    	password:            string,
    	// For encrypted members, and at 7z's open for an encrypted header
    	max_key_derivations: int,
    }
     

    How to read members

    Related Procedures With Parameters

    SevenZ_Error ¶

    SevenZ_Error :: enum u32 {
    	None, 
    	Invalid_Signature,   // No 7z signature header at the start, nor behind an executable's stub
    	Unsupported_Version, // The major version isn't 0
    	Header_CRC_Mismatch, // The start or next header's CRC-32 doesn't match
    	Invalid_Header,      // The header is malformed
    	Header_Too_Large,    // The header exceeds `HEADER_SIZE_MAX` or the memory limit
    	Header_Too_Deep,     // Encoded headers nest deeper than `HEADER_DEPTH_MAX`
    	Invalid_Folder,      // A folder's coders, bindings or streams are malformed
    	Truncated,           // The archive ends inside a header or packed stream
    	Size_Mismatch,       // A packed or unpacked size doesn't match the header or `File_Info.size`
    	CRC_Mismatch,        // The extracted data's CRC-32 doesn't match
    	Invalid_Name,        // A name that can't be written
    }
     

    7z errors

    Tar_Error ¶

    Tar_Error :: enum u32 {
    	None, 
    	Invalid_Checksum,          // A header block's checksum doesn't match
    	Invalid_Number,            // A numeric header field can't be parsed
    	Invalid_Size,              // A member's size is negative or too large
    	Truncated,                 // The archive ends inside a header or a member's data
    	Invalid_Pax_Record,        // A pax extended header record is malformed
    	Header_Too_Large,          // Long names or pax records exceed `HEADER_RECORD_MAX`
    	Unsupported_GNU_Extension, // A GNU multi-volume member, or sparse keys of an unknown version
    	Invalid_Name,              // An empty name, or a NUL in a name or link target
    	Size_Mismatch,             // A writer's reader didn't produce `File_Info.size` bytes
    	Invalid_Sparse_Map,        // A sparse member's map is malformed
    }
     

    tar errors

    Target ¶

    Target :: struct {
    	path:  string,
    	// The member's path, ignoring a leading `./` or trailing `/`
    	to:    Target_Destination,
    	found: bool,
    }
     

    A member for extract_many to extract, and where to

    Target_Destination ¶

    Target_Destination :: union {
    	string, 
    	^[dynamic]u8, 
    	io.Stream, 
    }
     

    Where an extracted target goes: a file path, a byte buffer or a writer

    Walk ¶

    Walk :: struct {
    	root:      string,
    	walker:    os.Walker,
    	name:      [dynamic]u8,
    	prefix:    int,
    	entries:   [dynamic]Walked_Entry,
    	index:     int,
    	sorted:    bool,
    	err:       Error,
    	allocator: runtime.Allocator,
    }

    Walked_Entry ¶

    Walked_Entry :: struct {
    	name: string,
    	info: os.File_Info,
    }

    Zip_Error ¶

    Zip_Error :: enum u32 {
    	None, 
    	End_Not_Found,             // No end of central directory record
    	Invalid_End,               // The end of central directory record is malformed
    	Invalid_Zip64_End,         // The zip64 end record or its locator is malformed
    	Invalid_Central_Directory, // The central directory is malformed or its count is wrong
    	Invalid_Local_Header,      // A local file header is malformed
    	Invalid_Extra_Field,       // An extra field is malformed
    	Split_Archive,             // The archive spans several disks
    	CRC_Mismatch,              // The extracted data's CRC-32 doesn't match
    	Size_Mismatch,             // A packed or unpacked size doesn't match the header or `File_Info.size`
    	Truncated,                 // The archive ends inside a record or a member's data
    	Invalid_Name,              // A name that can't be written
    	Field_Too_Long,            // A name, comment or extra field is too long
    	Too_Large,                 // A member outgrew 4 GiB without a zip64 local header
    	Overlapping_Member,        // A member's data overlaps another member or the central directory
    	Local_Header_Mismatch,     // A local header disagrees with its central directory entry
    	Unsupported_Password,      // A password AES-256 writing can't use: not ASCII, or over 99 bytes
    }
     

    zip errors

    Constants

    DETECT_HEAD_SIZE ¶

    DETECT_HEAD_SIZE :: 1024
     

    How many leading bytes which looks at

    DOS_READ_ONLY ¶

    DOS_READ_ONLY :: 0x01
     

    DOS attribute bits, as in File_Info.dos_attributes

    LINK_TARGET_MAX :: 4096
     

    The longest symlink target, in bytes, that zip and 7z read and write

    UNIX_BLOCK_DEVICE ¶

    UNIX_BLOCK_DEVICE :: 0o060000

    UNIX_CHARACTER_DEVICE ¶

    UNIX_CHARACTER_DEVICE :: 0o020000

    UNIX_DIRECTORY ¶

    UNIX_DIRECTORY :: 0o040000

    UNIX_NAMED_PIPE ¶

    UNIX_NAMED_PIPE :: 0o010000

    UNIX_PERMISSION_MASK ¶

    UNIX_PERMISSION_MASK :: 0o7777

    UNIX_TYPE_MASK ¶

    UNIX_TYPE_MASK :: 0o170000
     

    Unix file type and permission bits, as in File_Info.unix_mode

    Variables

    This section is empty.

    Procedures

    check_member_path ¶

    check_member_path :: proc(path: string, windows: bool = ODIN_OS == .Windows) -> (err: Error) {…}
     

    Checks that a member path is safe to extract below a directory

    Inputs:

    • path The member's path
    • windows Also apply Windows' rules: \ separates, and control and reserved characters, reserved names, and trailing dots and spaces are refused (default: ODIN_OS == .Windows)

    Returns:

    close ¶

    close :: proc(a: ^Archive) {…}
     

    Closes an archive and frees its memory

    Inputs:

    close_member ¶

    close_member :: proc(r: io.Stream) {…}
     

    Closes a reader from open_member and frees it

    Inputs:

    • r The member's reader

    extract_all ¶

    extract_all :: proc(
    	a:         ^Archive, 
    	dir:       string, 
    	options:   Extract_Options = Extract_Options{}, 
    	allocator := context.allocator, 
    ) -> (err: Error) {…}
     

    Extracts every regular file and directory into a directory

    Other types of member give General_Error.Skipped_Entry_Type.

    Allocates Using Provided Allocator

    Inputs:

    • a An open archive
    • dir The destination, created if missing
    • options Overwriting, limits and the password (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err The first error; extraction carries on past a failed member

    extract_current_to_dir ¶

    extract_current_to_dir :: proc(
    	d:         ^Extractor, 
    	it:        ^Iterator, 
    	fi:        File_Info, 
    	path:      string, 
    	overwrite: bool = false, 
    ) -> (err: Error) {…}
     

    Extracts the current member below the extractor's directory

    Creates missing parent directories, but refuses to write through a symlink. A file that fails halfway is removed.

    Inputs:

    • d The extractor
    • it The iterator, on the member iterate returned last
    • fi The member's info, from iterate
    • path Where to put it, relative to the directory; usually fi.path
    • overwrite Replace an existing file, whatever the extractor's options say (default: false)

    Returns:

    extract_current_to_dynamic ¶

    extract_current_to_dynamic :: proc(
    	it:      ^Iterator, 
    	output:  ^[dynamic]u8, 
    	options: Read_Options = Read_Options{}, 
    ) -> (err: Error) {…}
     

    Reads the current member's data into a buffer, decompressed and checked

    Inputs:

    • it The iterator, on the member iterate returned last
    • output Replaced by the member's data, grown with its own allocator; emptied on an error
    • options The member's password, if encrypted (default: {})

    Returns:

    extract_current_to_writer ¶

    extract_current_to_writer :: proc(
    	it:      ^Iterator, 
    	w:       io.Stream, 
    	options: Read_Options = Read_Options{}, 
    ) -> (err: Error) {…}
     

    Writes the current member's data to a writer, decompressed and checked

    Inputs:

    • it The iterator, on the member iterate returned last
    • w Where the member's data is written
    • options The member's password, if encrypted (default: {})

    Returns:

    extract_iterate ¶

    extract_iterate :: proc(it: ^Extract_Iterator) -> (target: ^Target, index: int, ok: bool) {…}
     

    Extracts the next member that matches a target

    Only regular files are extracted; another type of member gives General_Error.Skipped_Entry_Type. On js, a path target gives General_Error.Incompatible_Options.

    Inputs:

    • it The iterator

    Returns:

    • target The matched target
    • index Its index in targets
    • ok false once every target is found (unless last_wins), at the archive's end, or on an error reading the archive; extract_iterator_error has this member's error, or the last one

    extract_iterator_create ¶

    extract_iterator_create :: proc(
    	a:         ^Archive, 
    	targets:   []Target, 
    	options:   Extract_Options = Extract_Options{}, 
    	allocator := context.allocator, 
    ) -> (it: Extract_Iterator) {…}
     

    Creates an iterator that extracts targets in one pass over an archive

    Allocates Using Provided Allocator

    Inputs:

    • a An open archive
    • targets The members to extract and where to; their found flags are reset
    • options Overwriting, limits and the password (default: {})
    • allocator (default: context.allocator)

    Returns:

    extract_iterator_destroy ¶

    extract_iterator_destroy :: proc(it: ^Extract_Iterator) {…}
     

    Destroys an extract iterator

    Inputs:

    • it The iterator

    extract_iterator_error ¶

    @(require_results)
    extract_iterator_error :: proc(it: ^Extract_Iterator) -> (path: string, err: Error) {…}
     

    Tells why the last extract_iterate failed

    Inputs:

    • it The iterator

    Returns:

    • path The path of the member the error is about, if any
    • err The error of the member extract_iterate just returned; once it returns false, the last error of the pass, or nil

    extract_many ¶

    extract_many :: proc(
    	a:         ^Archive, 
    	targets:   []Target, 
    	options:   Extract_Options = Extract_Options{}, 
    	allocator := context.allocator, 
    ) -> (err: Error) {…}
     

    Extracts targets in one pass over an archive

    Only regular files are extracted; another type of member gives General_Error.Skipped_Entry_Type. A target that matches no member keeps found unset.

    Allocates Using Provided Allocator

    Inputs:

    • a An open archive
    • targets The members to extract and where to; their found flags are reset
    • options Overwriting, limits and the password (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err The first error; extraction carries on past a failed target

    extract_to_dynamic ¶

    extract_to_dynamic :: proc(
    	a:       ^Archive, 
    	handle:  Handle, 
    	output:  ^[dynamic]u8, 
    	options: Read_Options = Read_Options{}, 
    ) -> (err: Error) {…}
     

    Reads a member's data into a buffer, decompressed and checked

    Inputs:

    • a An open archive
    • handle The member, from File_Info.handle or find
    • output Replaced by the member's data, grown with its own allocator; emptied on an error
    • options The member's password, if encrypted (default: {})

    Returns:

    extract_to_writer ¶

    extract_to_writer :: proc(
    	a:       ^Archive, 
    	handle:  Handle, 
    	w:       io.Stream, 
    	options: Read_Options = Read_Options{}, 
    ) -> (err: Error) {…}
     

    Writes a member's data to a writer, decompressed and checked

    Inputs:

    • a An open archive
    • handle The member, from File_Info.handle or find
    • w Where the member's data is written
    • options The member's password, if encrypted (default: {})

    Returns:

    extractor_create ¶

    extractor_create :: proc(
    	dir:       string, 
    	options:   Extract_Options = Extract_Options{}, 
    	allocator := context.allocator, 
    ) -> (d: Extractor, err: Error) {…}
     

    Creates an extractor, which extracts members into a directory one at a time

    Allocates Using Provided Allocator

    Inputs:

    • dir The destination, created if missing
    • options Overwriting, limits and the password (default: {})
    • allocator (default: context.allocator)

    Returns:

    • d The extractor; destroy it with extractor_destroy
    • err An error creating dir, or nil

    extractor_destroy ¶

    extractor_destroy :: proc(d: ^Extractor) {…}
     

    Destroys an extractor

    Inputs:

    • d The extractor

    file_info_clone ¶

    file_info_clone :: proc(
    	fi:        File_Info, 
    	allocator: runtime.Allocator, 
    ) -> (cloned: File_Info, err: runtime.Allocator_Error) {…}
     

    Clones a member's info, so it outlives the iterator or reader it came from

    Allocates Using Provided Allocator

    Inputs:

    • fi The member's info
    • allocator The allocator for its strings

    Returns:

    • cloned The clone; free it with file_info_delete
    • err An allocator error if one occurred, nil otherwise

    file_info_delete ¶

    file_info_delete :: proc(fi: File_Info, allocator: runtime.Allocator) {…}
     

    Frees a member's info from file_info_clone

    Inputs:

    find ¶

    find :: proc(
    	a:    ^Archive, 
    	path: string, 
    ) -> (fi: File_Info, handle: Handle, ok: bool, err: Error) {…}
     

    Finds a member by path

    NOTE: Of several members with the path, zip and 7z find the first.

    tar finds the next one after its current member, wrapping around. Searching forward first saves decompressing a compressed tar again from the start, and lets tar.find work on a pipe.

    Inputs:

    • a An open archive
    • path The member's path, ignoring a leading ./ or trailing /

    Returns:

    • fi The member's info; its strings last as long as those from iterate
    • handle The member, for extract and open_member
    • ok false if no member has the path
    • err An error reading the archive (tar), or nil

    info ¶

    info :: proc(a: ^Archive) -> (info: Archive_Info) {…}
     

    Summarizes an archive

    Inputs:

    • a An open archive

    Returns:

    • info Its format, member count, comment and compression method

    iterate ¶

    iterate :: proc(it: ^Iterator) -> (fi: File_Info, index: int, ok: bool) {…}
     

    Moves to the next member

    Inputs:

    • it The iterator

    Returns:

    • fi The member's info; its strings last until the next iterate (until close for zip and 7z), so keep them with file_info_clone
    • index The member's index, as in fi.handle
    • ok false after the last member or on an error; iterator_error tells which

    iterator_create ¶

    iterator_create :: proc(a: ^Archive) -> (it: Iterator) {…}
     

    Creates an iterator over an archive's members, in storage order

    NOTE: A tar reader has one position, which its iterators, find, extract and open_member share; creating an iterator rewinds it.

    Inputs:

    • a An open archive

    Returns:

    iterator_destroy ¶

    iterator_destroy :: proc(it: ^Iterator) {…}
     

    Destroys an iterator, along with the reader open_current returned

    Inputs:

    • it The iterator

    iterator_error ¶

    @(require_results)
    iterator_error :: proc(it: ^Iterator) -> (path: string, err: Error) {…}
     

    Tells why iteration stopped

    Inputs:

    • it The iterator

    Returns:

    • path The path of the member the error is about, if any
    • err The error that stopped iteration, nil if it reached the end

    open_current ¶

    open_current :: proc(
    	it:      ^Iterator, 
    	options: Read_Options = Read_Options{}, 
    ) -> (r: io.Stream, err: Error) {…}
     

    Opens the current member's data as a reader, which decompresses as it is read

    Inputs:

    • it The iterator, on the member iterate returned last
    • options The member's password, if encrypted (default: {})

    Returns:

    open_from_bytes ¶

    open_from_bytes :: proc(
    	data:         []u8, 
    	options:      compress.Options = compress.Options{}, 
    	allocator := context.allocator, 
    	read_options: Read_Options = Read_Options{}, 
    ) -> (a: Archive, err: Error) {…}
     

    Opens an archive held in memory, detecting its format

    Data which doesn't recognize opens as zip when it ends in a zip archive, as a self-extracting .exe does, else as 7z when it is an executable (MZ, ELF or Mach-O) with a 7z archive starting in its first sevenz.SFX_SEARCH_MAX bytes.

    Allocates Using Provided Allocator

    Inputs:

    • data The archive's bytes; they must stay valid until close
    • options Limits and progress callback for the decoders, see compress.Options (default: {})
    • allocator (default: context.allocator)
    • read_options 7z's default password and key-derivation limit; the others ignore them (default: {})

    Returns:

    open_from_path ¶

    open_from_path :: proc(
    	path:         string, 
    	options:      compress.Options = compress.Options{}, 
    	allocator := context.allocator, 
    	read_options: Read_Options = Read_Options{}, 
    ) -> (a: Archive, err: Error) {…}
     

    Opens an archive file, detecting its format

    Data which doesn't recognize opens as zip when it ends in a zip archive, as a self-extracting .exe does, else as 7z when it is an executable (MZ, ELF or Mach-O) with a 7z archive starting in its first sevenz.SFX_SEARCH_MAX bytes.

    Allocates Using Provided Allocator

    Inputs:

    • path The archive's path
    • options Limits and progress callback for the decoders, see compress.Options (default: {})
    • allocator (default: context.allocator)
    • read_options 7z's default password and key-derivation limit; the others ignore them (default: {})

    Returns:

    open_from_stream ¶

    open_from_stream :: proc(
    	s:            io.Stream, 
    	options:      compress.Options = compress.Options{}, 
    	allocator := context.allocator, 
    	read_options: Read_Options = Read_Options{}, 
    ) -> (a: Archive, err: Error) {…}
     

    Opens an archive from a stream, detecting its format

    Data which doesn't recognize opens as zip when it ends in a zip archive, as a self-extracting .exe does, else as 7z when it is an executable (MZ, ELF or Mach-O) with a 7z archive starting in its first sevenz.SFX_SEARCH_MAX bytes.

    Allocates Using Provided Allocator

    Inputs:

    • s The archive; it must seek, and stay open until close, which leaves it open
    • options Limits and progress callback for the decoders, see compress.Options (default: {})
    • allocator (default: context.allocator)
    • read_options 7z's default password and key-derivation limit; the others ignore them (default: {})

    Returns:

    open_member ¶

    open_member :: proc(
    	a:       ^Archive, 
    	handle:  Handle, 
    	options: Read_Options = Read_Options{}, 
    ) -> (r: io.Stream, err: Error) {…}
     

    Opens a member's data as a reader, which decompresses as it is read

    Inputs:

    • a An open archive
    • handle The member, from File_Info.handle or find
    • options The member's password, if encrypted (default: {})

    Returns:

    read_link :: proc(
    	it:        ^Iterator, 
    	options:   Read_Options = Read_Options{}, 
    	allocator := context.allocator, 
    ) -> (target: string, err: Error) {…}
     

    Reads the current member's link target

    Allocates Using Provided Allocator

    Inputs:

    • it The iterator, on the member iterate returned last
    • options The member's password, if encrypted (default: {})
    • allocator (default: context.allocator)

    Returns:

    • target The symlink's target (tar: also a hard link's), empty for other members; delete it
    • err General_Error.No_Current_Member if iterate hasn't returned a member, or the member's error, or nil

    to_os_file_type ¶

    to_os_file_type :: proc "contextless" (fi: File_Info) -> (type: os.File_Type) {…}
     

    Converts a member's entry type to os.File_Type

    Inputs:

    • fi The member's info

    Returns:

    • type The matching file type; .Undetermined for hard links, anti-items and unknown types

    to_os_permissions ¶

    to_os_permissions :: proc "contextless" (fi: File_Info) -> (permissions: os.Permissions) {…}
     

    Converts a member's Unix mode to os.Permissions

    Inputs:

    • fi The member's info

    Returns:

    • permissions The 0o777 bits of fi.unix_mode

    which ¶

    which :: proc(head: []u8) -> (format: Format) {…}
     

    Detects an archive's format from its first bytes

    An archive behind other data, such as a self-extracting .exe's stub, isn't recognized; open still finds a zip archive there, or a 7z archive behind an executable's stub.

    Inputs:

    Returns:

    • format The first registered format that recognizes them, trying 7z, zip and tar in that order, or .Unknown

    Procedure Groups

    extract ¶

    extract :: proc{
    	extract_to_writer,
    	extract_to_dynamic,
    }
    
     

    Extracts a member's data to a writer or into a buffer

    extract_current ¶

     

    Extracts the current member's data to a writer or into a buffer

    open ¶

     

    Opens an archive from a path, a byte slice or a stream, detecting its format

    Source Files

    Generation Information

    Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-28 21:05:09.772358800 +0000 UTC