package core:archive/sevenz

⌘K
Ctrl+K
or
/

    Overview

    Reads, writes and updates 7z archives, as described by DOC/7zFormat.txt in Igor Pavlov's public domain LZMA SDK.

    open reads an archive from a path, a byte slice or a seekable io.Stream, also behind the stub of a self-extracting executable (MZ, ELF or Mach-O) when the archive starts in its first SFX_SEARCH_MAX bytes; update, remove_entry and rename_entry keep the stub. create starts a new archive at a path or on a seekable io.Stream, write_entry adds a member from a byte slice or an io.Reader, write_directory adds a whole tree, and commit finishes the archive. update appends members to an existing archive in place, and write_anti_item marks a path as deleted; at a path, remove_entry and rename_entry rewrite it, re-encoding a solid folder that loses only some of its members. close releases a reader or a writer. A crash during an update at a path leaves the last committed archive. At a path, readers take a shared lock and writers an exclusive one, except on wasi.

    Members are read through an iterator: iterator_create walks them in storage order, which decodes each solid folder only once, iterate gives each one's archive.File_Info, and extract_current unpacks it to an io.Writer, or open_current streams it through an io.Reader. find looks a member up by path for extract or open_member, and core:archive's extract_all unpacks a whole archive below a directory. Extraction checks each member's CRC-32.

    The methods are Copy, LZMA, LZMA2 (the writer's default), PPMd, Deflate, Deflate64 and bzip2, and the filters Delta, BCJ (x86, PowerPC, IA-64, ARM, ARM Thumb, SPARC, ARM64 and RISC-V), BCJ2, Swap2 and Swap4. The writer picks a filter from the data unless told otherwise, and can pack members into solid folders, capped by size and member count and ordered by name or extension. Encryption is 7-Zip's AES-256, which also covers the header unless unencrypted_header is set; archive.Read_Options takes the password and caps the key derivations per reader. Written headers are compressed unless plain_header is set.

    Reading and writing take an optional progress callback, for a UI's progress bar, which can also cancel. A deterministic mode writes reproducible archives.

    Not supported: writing new self-extracting archives, reading or writing multi-volume archives, and methods beyond those above, such as the Zstandard and LZ4 of 7-Zip's forks. On js, only byte slices and streams work.

    Types

    Entry ¶

    Entry :: struct {
    	path:              string,
    	// The name, converted from UTF-16 to UTF-8
    	raw_path:          []u8,
    	// The name's UTF-16LE bytes as stored, without the terminator
    	size:              i64,
    	// The data's size once unpacked, in bytes
    	crc:               runtime.Maybe($T=u32),
    	// The data's CRC-32, if stored
    	folder:            int,
    	// The folder (block) holding the data, -1 without data
    	folder_offset:     i64,
    	// Where the data starts in the folder's decoded output
    	has_stream:        bool,
    	// `false` for a directory, an empty file or an anti-item
    	is_directory:      bool,
    	// `true` for a directory
    	is_anti:           bool,
    	// An anti-item: applied as an update, it deletes `path`
    	attributes:        runtime.Maybe($T=u32),
    	// DOS attributes; with `UNIX_EXTENSION`, the Unix mode << 16
    	creation_time:     runtime.Maybe($T=u64),
    	// Windows FILETIME, as are the other times
    	access_time:       runtime.Maybe($T=u64),
    	// The last access, if stored
    	modification_time: runtime.Maybe($T=u64),
    	// The last change, if stored
    	start_position:    runtime.Maybe($T=u64),
    }
     

    A member's record in the archive header, from current_entry

    Entry_Data ¶

    Entry_Data :: union {
    	[]u8, 
    	io.Stream, 
    }
     

    A regular file's data, for write_entry

    Related Procedures With Parameters

    Entry_Options ¶

    Entry_Options :: struct {
    	method:         archive.Method,
    	// `.Unknown` for the writer's
    	level:          runtime.Maybe($T=int),
    	// `nil`: the writer's for its method, else the default
    	filter:         Filter_Choice,
    	// `.Auto` for the writer's filter and distance
    	delta_distance: int,
    	// 1 to 256, for `.Delta`; 0 means 1
    	lzma:           runtime.Maybe($T=Options),
    	// LZMA and LZMA2 settings in place of the level's
    	ppmd:           runtime.Maybe($T=Properties),
    	// PPMd settings in place of the level's; variant H
    	password:       runtime.Maybe($T=string),
    	// `nil` for the writer's, `""` for none
    	replace:        bool,
    }
     

    One member's settings; all but replace stand in for the Writer_Options defaults

    Related Procedures With Parameters

    Filter_Choice ¶

    Filter_Choice :: enum u8 {
    	Auto,      // Picked from the data; x86 code may get BCJ2. In `Entry_Options`: the writer's
    	None, 
    	Delta,     // Byte-wise delta, over `delta_distance` bytes
    	BCJ_X86, 
    	BCJ_PPC, 
    	BCJ_IA64, 
    	BCJ_ARM, 
    	BCJ_ARMT, 
    	BCJ_SPARC, 
    	BCJ_ARM64, 
    	BCJ_RISCV, 
    	BCJ2,      // x86 branch converter with four streams
    	Swap2,     // Swaps the bytes of each 16-bit word
    	Swap4,     // Reverses the bytes of each 32-bit word
    }
     

    The filter a writer applies before compression

    Iterator ¶

    Iterator :: struct {
    	reader:  ^Reader,
    	index:   int,
    	decoder: Folder_Decoder,
    	member:  Member,
    }
     

    Walks a Reader's members, from iterator_create

    Related Procedures With Parameters

    Reader ¶

    Reader :: struct {
    	allocator:    runtime.Allocator,
    	options:      compress.Options,
    	store:        Store,
    	base:         i64,
    	file:         io.Stream,
    	journal:      []archive.Range,
    	header:       []u8,
    	owns_header:  bool,
    	header_start: i64,
    	streams:      Streams,
    	items:        []Entry,
    	names:        []u8,
    	index:        []Name_Index,
    	generation:   u32,
    	password:     string,
    	keys:         Key_Cache,
    }
     

    Reads a 7z archive, from open

    Related Procedures With Parameters

    Solid_Order ¶

    Solid_Order :: enum u8 {
    	Name,      // By path
    	Extension, // By kind of extension, as 7-Zip does, then by path
    }
     

    How write_directory orders the files in solid mode, after grouping them by filter

    Writer ¶

    Writer :: struct {
    	allocator:     runtime.Allocator,
    	options:       Writer_Options,
    	stream:        io.Stream,
    	disk:          archive.Disk,
    	start:         i64,
    	offset:        i64,
    	end:           i64,
    	pack_sizes:    [dynamic]i64,
    	folders:       [dynamic]Out_Folder,
    	files:         [dynamic]Out_File,
    	names:         [dynamic]u8,
    	name:          [dynamic]u8,
    	header:        [dynamic]u8,
    	chunk:         []u8,
    	head:          []u8,
    	filter_buffer: []u8,
    	cipher_buffer: []u8,
    	folder:        Open_Folder,
    	password:      string,
    	kdf_power:     int,
    	salt:          [16]u8,
    	salted:        bool,
    	keys:          Key_Cache,
    	ciphers:       [dynamic]Out_Cipher,
    	archive_in:    i64,
    	err:           archive.Error,
    	committed:     bool,
    	active:        bool,
    	mode:          Writer_Mode,
    	pack_pos:      i64,
    	old:           Reader,
    	old_length:    i64,
    	data_start:    i64,
    	saved:         []archive.Range,
    	kept:          [dynamic]int,
    	slots:         [dynamic]Update_Slot,
    	heads:         map[string]int,
    	guard:         bool,
    	journaled:     bool,
    	modified:      bool,
    	must_rewrite:  bool,
    	repacking:     bool,
    }
     

    Writes or updates a 7z archive, from create or update

    Related Procedures With Parameters

    Writer_Options ¶

    Writer_Options :: struct {
    	method:             archive.Method,
    	// `.Unknown` for LZMA2
    	level:              runtime.Maybe($T=int),
    	// `nil` for the method's default; clamped
    	filter:             Filter_Choice,
    	delta_distance:     int,
    	// 1 to 256, for `.Delta`; 0 means 1
    	lzma:               runtime.Maybe($T=Options),
    	// LZMA and LZMA2 settings in place of the level's
    	ppmd:               runtime.Maybe($T=Properties),
    	// PPMd settings in place of the level's; variant H
    	solid:              bool,
    	// Compresses like-set members together in blocks
    	solid_size:         i64,
    	// A block's data limit; 0 picks one by method
    	solid_files:        int,
    	// A block's member limit; 0 for none
    	solid_order:        Solid_Order,
    	creation_time:      bool,
    	// Stores creation times
    	access_time:        bool,
    	// Stores access times
    	plain_header:       bool,
    	// Leaves the header uncompressed, if not encrypted
    	deterministic:      bool,
    	// Reproducible: no times, sorted `write_directory`
    	password:           string,
    	// AES-256, members and header; not `deterministic`
    	kdf_power:          int,
    	// 2^`kdf_power` SHA-256 rounds per key; 0 means 19
    	unencrypted_header: bool,
    	// With a password, keeps the header's paths readable
    	no_sync:            bool,
    	options:            compress.Options,
    }
     

    A writer's settings; the methods are Store, LZMA, LZMA2, PPMd_H, BZip2, Deflate and Deflate64

    Related Procedures With Parameters

    Constants

    AES_POWER_DEFAULT ¶

    AES_POWER_DEFAULT :: 19
     

    The key-derivation power written when Writer_Options.kdf_power is 0, as 7-Zip does

    AES_POWER_MAX ¶

    AES_POWER_MAX :: 24
     

    The largest key-derivation power read or written: 2^24 SHA-256 rounds

    HEADER_SIZE_MAX ¶

    HEADER_SIZE_MAX :: i64(#config(SEVENZ_HEADER_SIZE_MAX, 1 << 30))
     

    The largest header a reader decodes, in bytes; the decoders' memory limit may lower it

    KDF_LIMIT_DEFAULT ¶

    KDF_LIMIT_DEFAULT :: 16
     

    How many key derivations a reader allows when Read_Options.max_key_derivations is 0

    SFX_SEARCH_MAX ¶

    SFX_SEARCH_MAX :: i64(#config(SEVENZ_SFX_SEARCH_MAX, 4 << 20))

    UPDATE_SAVED_MAX ¶

    UPDATE_SAVED_MAX :: 64 << 20
     

    An update at a path with a larger old header rewrites the archive instead of appending in place

    Variables

    This section is empty.

    Procedures

    close_member ¶

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

    Closes a reader from open_member and frees it

    Inputs:

    • reader The member's reader

    close_reader ¶

    close_reader :: proc(r: ^Reader) {…}
     

    Closes a reader and frees its memory

    Inputs:

    close_writer ¶

    close_writer :: proc(sw: ^Writer) {…}
     

    Closes a writer and frees its memory

    Without commit, an update is rolled back and a new archive at a path is discarded; a new archive on a stream is left unfinished.

    Inputs:

    commit ¶

    commit :: proc(sw: ^Writer) -> (err: archive.Error) {…}
     

    Finishes the archive: writes the header and, at a path, puts the archive in place

    Committing again does nothing. Afterwards, only close is left to call.

    Inputs:

    • sw An open writer

    Returns:

    • err The error that stopped the writer earlier, the commit's own error, or nil

    create_from_path ¶

    create_from_path :: proc(
    	sw:        ^Writer, 
    	path:      string, 
    	options:   Writer_Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: archive.Error) {…}
     

    Starts a new 7z archive at a path

    The archive is written to path plus archive.TEMP_SUFFIX, which commit renames over path. An existing archive at path is locked meanwhile, except on wasi.

    Allocates Using Provided Allocator

    Inputs:

    • sw The writer; close it when done, it is left closed on an error
    • path Where the archive goes
    • options The default method, level, filter and password, solid blocks, and more (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err Bad options as for create_from_stream, General_Error.Busy if another process holds the archive, an OS error, or nil

    create_from_stream ¶

    create_from_stream :: proc(
    	sw:        ^Writer, 
    	s:         io.Stream, 
    	options:   Writer_Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: archive.Error) {…}
     

    Starts a new 7z archive on a stream

    Allocates Using Provided Allocator

    Inputs:

    • sw The writer; close it when done, it is left closed on an error
    • s Where the archive goes, from its current position; it must seek, as commit writes the start header last
    • options The default method, level, filter and password, solid blocks, and more (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err General_Error.Incompatible_Options or General_Error.Unsupported_Method for bad options, General_Error.Not_Seekable, io.Error.Unsupported if s can't write, or nil

    current_entry ¶

    current_entry :: proc(it: ^Iterator) -> (entry: ^Entry) {…}
     

    Returns the current member's entry in the archive header, for what File_Info leaves out

    Inputs:

    • it The iterator, on the member iterate returned last

    Returns:

    • entry The member's entry from the archive header, which lasts until close; nil if iterate hasn't returned a member

    extract_current_to_dynamic ¶

    extract_current_to_dynamic :: proc(
    	it:      ^Iterator, 
    	output:  ^[dynamic]u8, 
    	options: archive.Read_Options = archive.Read_Options{}, 
    ) -> (err: archive.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; else the one given at open (default: {})

    Returns:

    • err General_Error.No_Current_Member if iterate hasn't returned a member, an allocator error, the member's error, or nil

    extract_current_to_writer ¶

    extract_current_to_writer :: proc(
    	it:      ^Iterator, 
    	w:       io.Stream, 
    	options: archive.Read_Options = archive.Read_Options{}, 
    ) -> (err: archive.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; else the one given at open (default: {})

    Returns:

    • err General_Error.No_Current_Member if iterate hasn't returned a member, or the member's error, or nil

    extract_to_dynamic ¶

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

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

    In a solid folder, the folder is decoded from its start up to the member.

    Inputs:

    • r An open reader
    • 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; else the one given at open (default: {})

    Returns:

    • err General_Error.Not_Found for a stale handle, an allocator error, the member's error, or nil

    extract_to_writer ¶

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

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

    In a solid folder, the folder is decoded from its start up to the member.

    Inputs:

    • r An open reader
    • handle The member, from File_Info.handle or find
    • w Where the member's data is written
    • options The member's password, if encrypted; else the one given at open (default: {})

    Returns:

    • err General_Error.Not_Found for a stale handle, the member's error, or nil

    find ¶

    find :: proc(
    	r:    ^Reader, 
    	path: string, 
    ) -> (fi: archive.File_Info, handle: archive.Handle, ok: bool, err: archive.Error) {…}
     

    Finds a member by path

    NOTE: Of several members with the path, the first in storage order is found.

    Inputs:

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

    Returns:

    • fi The member's info; its strings last until close
    • handle The member, for extract and open_member
    • ok false if no member has the path
    • err Always nil: the header was read at open

    info ¶

    info :: proc(r: ^Reader) -> (info: archive.Archive_Info) {…}
     

    Summarizes an archive

    Inputs:

    • r An open reader

    Returns:

    • info Its format and member count, and the method all folders share, else .Unknown

    iterate ¶

    iterate :: proc(it: ^Iterator) -> (fi: archive.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 close
    • index The member's index, as in fi.handle
    • ok false after the last member

    iterator_create ¶

    iterator_create :: proc(r: ^Reader) -> (it: Iterator) {…}
     

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

    Reading members in this order decodes each solid folder once.

    Inputs:

    • r An open reader

    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: archive.Error) {…}
     

    Tells why iteration stopped

    Inputs:

    • it The iterator

    Returns:

    • path Always empty
    • err Always nil: the header was read at open

    lzma_options_7zip ¶

    lzma_options_7zip :: proc "contextless" (level: int) -> (options: compress_lzma.Options) {…}
     

    Returns the LZMA settings 7-Zip uses for a level, for Writer_Options.lzma

    Inputs:

    • level The level, clamped to 0 through 9

    Returns:

    • options 7-Zip's dictionary size, match finder and match lengths for the level

    open_current ¶

    open_current :: proc(
    	it:      ^Iterator, 
    	options: archive.Read_Options = archive.Read_Options{}, 
    ) -> (reader: io.Stream, err: archive.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; else the one given at open (default: {})

    Returns:

    • reader The member's reader; it belongs to the iterator and lasts until the next iterate or open_current
    • err General_Error.No_Current_Member if iterate hasn't returned a member, or the member's error, or nil

    open_from_bytes ¶

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

    Opens a 7z archive held in memory

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; close it when done, it is left closed on an error
    • 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 The default password, which an encrypted header needs, and the key-derivation limit (default: {})

    Returns:

    • err A SevenZ_Error for a malformed archive, General_Error.Encrypted or General_Error.Wrong_Password for an encrypted header, or nil

    open_from_path ¶

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

    Opens a 7z archive file

    The file is share-locked until close, except on wasi. After a crashed update, the reader sees the last committed state, as the update's journal records it.

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; close it when done, it is left closed on an error
    • path The archive's path
    • options Limits and progress callback for the decoders, see compress.Options (default: {})
    • allocator (default: context.allocator)
    • read_options The default password, which an encrypted header needs, and the key-derivation limit (default: {})

    Returns:

    • err General_Error.Busy while a writer holds the file, an OS error, a SevenZ_Error for a malformed archive, General_Error.Encrypted or General_Error.Wrong_Password for an encrypted header, or nil

    open_from_stream ¶

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

    Opens a 7z archive from a stream

    Allocates Using Provided Allocator

    Inputs:

    • r The reader; close it when done, it is left closed on an error
    • s The archive; it must read at an offset or seek, report its size, 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 The default password, which an encrypted header needs, and the key-derivation limit (default: {})

    Returns:

    • err General_Error.Not_Seekable, a SevenZ_Error for a malformed archive, General_Error.Encrypted or General_Error.Wrong_Password for an encrypted header, or nil

    open_member ¶

    open_member :: proc(
    	r:         ^Reader, 
    	handle:    archive.Handle, 
    	options:   archive.Read_Options = archive.Read_Options{}, 
    	allocator := context.allocator, 
    ) -> (reader: io.Stream, err: archive.Error) {…}
     

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

    In a solid folder, the folder is decoded from its start up to the member.

    Allocates Using Provided Allocator

    Inputs:

    • r An open reader
    • handle The member, from File_Info.handle or find
    • options The member's password, if encrypted; else the one given at open (default: {})
    • allocator (default: context.allocator)

    Returns:

    • reader The member's reader; close it with close_member
    • err General_Error.Not_Found for a stale handle, the member's error, or nil
    read_link :: proc(
    	it:        ^Iterator, 
    	options:   archive.Read_Options = archive.Read_Options{}, 
    	allocator := context.allocator, 
    ) -> (target: string, err: archive.Error) {…}
     

    Reads the current member's link target, which 7z stores as the member's data

    Allocates Using Provided Allocator

    Inputs:

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

    Returns:

    • target The symlink's target, empty for other members; delete it
    • err General_Error.No_Current_Member if iterate hasn't returned a member, General_Error.Limit_Exceeded past archive.LINK_TARGET_MAX, the member's error, or nil

    remove_entry ¶

    remove_entry :: proc(sw: ^Writer, path: string) -> (err: archive.Error) {…}
     

    Removes a member, taking effect at commit

    Inputs:

    • sw A writer from update_from_path
    • path The member's path, ignoring a leading ./ or trailing /; every member with it goes

    Returns:

    • err General_Error.Incompatible_Options for a writer from elsewhere or a member added since the open, General_Error.Not_Found, or nil

    rename_entry ¶

    rename_entry :: proc(sw: ^Writer, old_path, new_path: string) -> (err: archive.Error) {…}
     

    Renames a member, taking effect at commit

    Inputs:

    • sw A writer from update_from_path
    • old_path The member's path, ignoring a leading ./ or trailing /; every member with it is renamed
    • new_path Its new path

    Returns:

    • err General_Error.Incompatible_Options for a writer from elsewhere or a member added since the open, General_Error.Not_Found, General_Error.Exists if new_path is taken, or nil

    update_from_path ¶

    update_from_path :: proc(
    	sw:        ^Writer, 
    	path:      string, 
    	options:   Writer_Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: archive.Error) {…}
     

    Opens a 7z archive at a path to append, replace, remove or rename members

    Appends happen in place, under a journal that rolls them back if the process dies before commit. A replacement, remove or rename, or an old header over UPDATE_SAVED_MAX bytes, makes commit write a new archive and rename it over the old one. The archive is locked until close, except on wasi.

    Allocates Using Provided Allocator

    Inputs:

    • sw The writer; close it when done, it is left closed on an error
    • path The archive's path
    • options The defaults for new members, and more; password also opens the archive (default: {})
    • allocator (default: context.allocator)

    Returns:

    • err Bad options as for create_from_stream, General_Error.Busy if another process holds the archive, an OS error, a SevenZ_Error for a malformed archive, or nil

    update_from_stream ¶

    update_from_stream :: proc(
    	sw:        ^Writer, 
    	s:         io.Stream, 
    	options:   Writer_Options = {}, 
    	allocator := context.allocator, 
    ) -> (err: archive.Error) {…}
     

    Opens a 7z archive on a stream to append members in place

    Allocates Using Provided Allocator

    Inputs:

    • sw The writer; close it when done, it is left closed on an error
    • s The archive; it must read, write and seek
    • options The defaults for new members, and more; password also opens the archive (default: {})
    • allocator (default: context.allocator)

    Returns:

    write_anti_item ¶

    write_anti_item :: proc(
    	sw:        ^Writer, 
    	path:      string, 
    	directory: bool = false, 
    ) -> (err: archive.Error) {…}
     

    Adds an anti-item: a member that tells 7-Zip, applying this archive as an update, to delete path

    Inputs:

    • sw An open writer
    • path The path to delete
    • directory Whether path is a directory (default: false)

    Returns:

    • err General_Error.Exists for a path an update already holds, or nil

    write_directory ¶

    write_directory :: proc(
    	sw:      ^Writer, 
    	dir:     string, 
    	prefix:  string = "", 
    	options: Entry_Options = {}, 
    ) -> (err: archive.Error) {…}
     

    Adds a directory tree: its directories, regular files and symlinks

    Other file types are skipped. With deterministic or solid, members go in sorted order; with solid, files are first grouped by filter, then ordered by solid_order.

    Inputs:

    • sw An open writer
    • dir The directory to add
    • prefix Prepended to every member path; when set, dir itself is added, named prefix (default: "")
    • options Every member's method, level, filter and password, in place of the writer's, and whether they replace the members an archive being updated has at their paths (default: {})

    Returns:

    write_entry_simple ¶

    write_entry_simple :: proc(
    	sw:      ^Writer, 
    	name:    string, 
    	data:    Entry_Data = nil, 
    	options: Entry_Options = {}, 
    ) -> (err: archive.Error) {…}
     

    Adds a regular file, stamped with the current time

    Inputs:

    • sw An open writer
    • name The member's path
    • data The file's data, as bytes or a reader (default: nil)
    • options This member's method, level, filter and password, in place of the writer's (default: {})

    Returns:

    write_entry_with_info ¶

    write_entry_with_info :: proc(
    	sw:      ^Writer, 
    	fi:      archive.File_Info, 
    	data:    Entry_Data = nil, 
    	options: Entry_Options = {}, 
    ) -> (err: archive.Error) {…}
     

    Adds a member described by a File_Info

    An error after part of the member was written stops the writer: later calls return it.

    Inputs:

    • sw An open writer
    • fi The member's path, type and metadata; a regular file, a directory or a symlink. size may be -1 for a reader of unknown size
    • data A regular file's data, as bytes or a reader; nil for other types (default: nil)
    • options This member's method, level, filter and password, in place of the writer's, and whether it replaces the members an archive being updated has at its path (default: {})

    Returns:

    • err General_Error.Unsupported_Entry, General_Error.Incompatible_Options for data on a non-file or for replacing a member in an update on a stream, General_Error.Exists for a path an update already holds, unless replace is set and the archive held it when opened, SevenZ_Error.Size_Mismatch if the reader doesn't give fi.size bytes, or nil

    Procedure Groups

    close ¶

    close :: proc{
    	close_reader,
    	close_writer,
    }
    
     

    Closes a reader or a writer

    create ¶

    create :: proc{
    	create_from_path,
    	create_from_stream,
    }
    
     

    Starts a new 7z archive at a path or on a stream

    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 a 7z archive from a path, a byte slice or a stream

    update ¶

    update :: proc{
    	update_from_path,
    	update_from_stream,
    }
    
     

    Opens a 7z archive at a path or on a stream for changes

    write_entry ¶

    write_entry :: proc{
    	write_entry_with_info,
    	write_entry_simple,
    }
    
     

    Adds a member described by a File_Info, or a regular file by name

    Source Files

    Generation Information

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