package core:archive
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:
opendetects the format and opens an archive from a path, a byte slice or a seekableio.Stream, self-extracting zip and 7z archives includediterator_createanditeratelist members in storage order;findlooks one up by path- Members are extracted to an
io.Writeror streamed through anio.Reader File_Infodescribes a member the same way in every format
Extracting:
extract_allandextract_current_to_dirwrite members below a directory; paths that escape it or cross a symlink are refusedextract_manyextracts members chosen by path to files, buffers or writers, in one passExtract_Optionscaps the total size and the compression ratio- On js only byte slices and streams are supported; the path procs are left out
Packages 3
| sevenz | Reads, writes and updates 7z archives, as described by DOC/7zFormat.txt in Igor Pavlov's | |
| tar | Reads and writes tar archives: v7, ustar and pax as specified by POSIX.1-2024, and GNU tar's. | |
| zip | Reads, writes and updates ZIP archives, as specified by version 6.3.10 (November 2022) of |
Index
Types (30)
- Archive
- Archive_Info
- Disk
- Entry_Type
- Error
- Extract_Iterator
- Extract_Options
- Extractor
- File_Info
- Filter
- Filters
- Format
- Format_Procs
- General_Error
- Handle
- Iterator
- Journal
- Journal_Range
- Lock_Kind
- Method
- OS_Error
- Range
- Read_Options
- SevenZ_Error
- Tar_Error
- Target
- Target_Destination
- Walk
- Walked_Entry
- Zip_Error
Constants (21)
Variables (0)
This section is empty.
Procedures (33)
Procedure Groups (3)
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
- open_from_bytes
- open_from_path
- open_from_stream
- open (procedure groups)
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
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
Error ¶
Error :: union { General_Error, Tar_Error, Zip_Error, SevenZ_Error, compress.Error, io.Error, os.Error, runtime.Allocator_Error, }
Any error from this package or the format packages
Related Procedures With Returns
- check_member_path
- extract_all
- extract_current_to_dir
- extract_current_to_dynamic
- extract_current_to_writer
- extract_iterator_error
- extract_many
- extract_to_dynamic
- extract_to_writer
- extractor_create
- find
- iterator_error
- open_current
- open_from_bytes
- open_from_path
- open_from_stream
- open_member
- read_link
- extract (procedure groups)
- extract_current (procedure groups)
- open (procedure groups)
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, }
Related Procedures With Parameters
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 ¶
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 ¶
Identifies a member for extract and open_member; take it from File_Info.handle or find
Related Procedures With Parameters
- extract_to_dynamic
- extract_to_writer
- open_member
- extract (procedure groups)
Journal ¶
Journal :: struct { old_length: i64, check_end: i64, ranges: [4]Journal_Range, range_count: int, }
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
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
- extract_current_to_dynamic
- extract_current_to_writer
- extract_to_dynamic
- extract_to_writer
- open_current
- open_from_bytes
- open_from_path
- open_from_stream
- open_member
- read_link
- extract (procedure groups)
- extract_current (procedure groups)
- open (procedure groups)
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 ¶
Where an extracted target goes: a file path, a byte buffer or a writer
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
DOS_ARCHIVE ¶
DOS_ARCHIVE :: 0x20
DOS_DIRECTORY ¶
DOS_DIRECTORY :: 0x10
JOURNAL_FIXED_SIZE ¶
JOURNAL_FIXED_SIZE :: 36
JOURNAL_MAGIC ¶
JOURNAL_MAGIC :: "ARCJOURN"
JOURNAL_RANGES_MAX ¶
JOURNAL_RANGES_MAX :: 4
JOURNAL_RANGE_SIZE ¶
JOURNAL_RANGE_SIZE :: 20
JOURNAL_SUFFIX ¶
JOURNAL_SUFFIX :: "-journal"
JOURNAL_TAIL_MAX ¶
JOURNAL_TAIL_MAX :: 64 * 1024
LINK_TARGET_MAX ¶
LINK_TARGET_MAX :: 4096
The longest symlink target, in bytes, that zip and 7z read and write
LOCK_ATTEMPTS ¶
LOCK_ATTEMPTS :: 8
TEMP_SUFFIX ¶
TEMP_SUFFIX :: "-temp"
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_REGULAR ¶
UNIX_REGULAR :: 0o100000
UNIX_SYMLINK ¶
UNIX_SYMLINK :: 0o120000
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 ¶
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:
- err
General_Error.Unsafe_Pathfor an absolute path, a..or a NUL,nilotherwise
close ¶
close :: proc(a: ^Archive) {…}
Closes an archive and frees its memory
Inputs:
- a The archive; a stream given to
open_from_streamis left open
close_member ¶
close_member :: proc(r: io.Stream) {…}
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
iteratereturned 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:
- err
General_Error.Skipped_Entry_Typefor anything but a regular file or a directory,General_Error.Unsafe_Pathifcheck_member_pathrefusespath,General_Error.Exists,General_Error.Limit_Exceeded, the member's error, ornil
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
iteratereturned 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:
- err
General_Error.No_Current_Memberifiteratehasn't returned a member, an allocator error, the member's error, ornil
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
iteratereturned last - w Where the member's data is written
- options The member's password, if encrypted (default: {})
Returns:
- err
General_Error.No_Current_Memberifiteratehasn't returned a member, or the member's error, ornil
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
falseonce every target is found (unlesslast_wins), at the archive's end, or on an error reading the archive;extract_iterator_errorhas 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
foundflags are reset - options Overwriting, limits and the password (default: {})
- allocator (default: context.allocator)
Returns:
- it The iterator; destroy it with
extract_iterator_destroy. Withlast_wins, anio.Writertarget makes it stop at once withGeneral_Error.Incompatible_Options
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_iteratejust returned; once it returnsfalse, the last error of the pass, ornil
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
foundflags 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.handleorfind - 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:
- err
General_Error.Not_Foundfor a stale handle, an allocator error, the member's error, ornil
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.handleorfind - w Where the member's data is written
- options The member's password, if encrypted (default: {})
Returns:
- err
General_Error.Not_Foundfor a stale handle, the member's error, ornil
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, ornil
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,
nilotherwise
file_info_delete ¶
Frees a member's info from file_info_clone
Inputs:
- fi The clone
- allocator The allocator given to
file_info_clone
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
extractandopen_member - ok
falseif 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 ¶
Moves to the next member
Inputs:
- it The iterator
Returns:
- fi The member's info; its strings last until the next
iterate(untilclosefor zip and 7z), so keep them withfile_info_clone - index The member's index, as in
fi.handle - ok
falseafter the last member or on an error;iterator_errortells which
iterator_create ¶
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:
- it The iterator; destroy it with
iterator_destroy
iterator_destroy ¶
iterator_destroy :: proc(it: ^Iterator) {…}
iterator_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,
nilif 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
iteratereturned last - options The member's password, if encrypted (default: {})
Returns:
- r The member's reader; it belongs to the iterator and lasts until the next
iterateoropen_current - err
General_Error.No_Current_Memberifiteratehasn't returned a member, or the member's error, ornil
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:
- a The archive;
closeit when done - err
General_Error.Unknown_Formatif no registered format recognizes it, the format's error, ornil
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:
- a The archive;
closeit when done - err
General_Error.Unknown_Formatif no registered format recognizes it, an OS error, the format's error, ornil
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:
- a The archive;
closeit when done - err
General_Error.Not_Seekable,General_Error.Unknown_Format, the format's error, ornil
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.handleorfind - options The member's password, if encrypted (default: {})
Returns:
- r The member's reader; close it with
close_member - err
General_Error.Not_Foundfor a stale handle, the member's error, ornil
read_link ¶
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
iteratereturned 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;
deleteit - err
General_Error.No_Current_Memberifiteratehasn't returned a member, or the member's error, ornil
to_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;
.Undeterminedfor 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
0o777bits offi.unix_mode
which ¶
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:
- head The archive's first bytes;
DETECT_HEAD_SIZEof them are enough
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 ¶
extract_current :: proc{ extract_current_to_writer, extract_current_to_dynamic, }
Extracts the current member's data to a writer or into a buffer
open ¶
open :: proc{ open_from_path, open_from_bytes, open_from_stream, }
Opens an archive from a path, a byte slice or a stream, detecting its format
Source Files
- archive.odin
- archive_os.odin
- common.odin
- common_os.odin
- extract.odin
- extract_os.odin
- internal.odin
- internal_os.odin
- internal_transaction.odin
- internal_transaction_os.odin
- (hidden platform specific files)
Generation Information
Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-28 21:05:09.772358800 +0000 UTC