Archive.Nif (Archive v0.4.0)
Proceed With Caution
The
Archive.Nif
module contains the functions that directly interact withlibarchive
. It is generally discouraged to interact with this library directly. If you find you need functionality not supported in the higher-level APIs, consider opening an issue first if the feature would be generally applicable or desireable.
Archive.Nif
provides direct Elixir
bindings to the libarchive
C API. Most of the functions
in this module are 1-to-1 mappings to the C API equivalent functions.
These functions work directly with references, rather than Archive
or Archive.Entry
structs.
As long as you use the ArchiveReaderResource
and ArchiveEntryResource
reference types, they will
be managed and garbage-collected by this module once created.
Most functions in this module may raise ErlangError
on failure. You should invoke most of
these functions using Archive.Nif.safe_call/2
to catch the errors and return them as :ok
or
an {:error, reason}
tuple
libarchive
APIs
libarchive
distinguishes the following APIs:
archive_read
Reading an Archive
Although
Archive
's high-level API takes care of all of the resource management for you, it can still be useful to understand how it works:
- Create new archive reader object
- Update any global reader properties as appropriate. These properties determine supported compressions, formats, etc.
- Open the archive
- Repeatedly call archive_read_next_header to get information about successive archive entries. Call archive_read_data to extract data for entries of interest.
- Cleanup archive reader object
archive-write
Creating an Archive
To create an archive:
- Ask archive_write_new for an archive writer object.
- Set any global properties. In particular, you should set the compression and format to use.
- Call archive_write_open to open the file (most people will use archive_write_open_file or archive_write_open_fd, which provide convenient canned I/O callbacks for you).
- For each entry:
- construct an appropriate struct archive_entry structure
- archive_write_header to write the header
- archive_write_data to write the entry data
- archive_write_close to close the output
- archive_write_free to cleanup the writer and release resources
archive_write_disk
Writing to Disk
To create objects on disk:
- Ask archive_write_disk_new for a new archive_write_disk object.
- Set any global properties. In particular, you probably want to set the options.
- For each entry:
- construct an appropriate struct archive_entry structure
- archive_write_header to create the file/dir/etc on disk
- archive_write_data to write the entry data
- archive_write_free to cleanup the writer and release resources s In particular, you can use this in conjunction with archive_read() to pull entries out of an archive and create them on disk.
It also has archive_read_extract
functions that combine reading with writing to disk.
Summary
Functions
archive_bzlib_version()
@spec archive_bzlib_version() :: binary()
archive_clear_error(arg1)
@spec archive_clear_error(term()) :: :ok
archive_compression(arg1)
@spec archive_compression(reference()) :: -2_147_483_648..2_147_483_647
archive_compression_name(arg1)
archive_entry_clear(arg1)
@spec archive_entry_clear(reference()) :: :ok
archive_entry_copy_stat(arg1, arg2)
@spec archive_entry_copy_stat( reference(), %{ atimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, birthtimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, blksize: -2_147_483_648..2_147_483_647, blocks: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, ctimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, dev: -2_147_483_648..2_147_483_647, flags: 0..4_294_967_295, gen: 0..4_294_967_295, gid: 0..4_294_967_295, ino: 0..18_446_744_073_709_551_615, lspare: -2_147_483_648..2_147_483_647, mode: 0..65535, mtimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, nlink: 0..65535, qspare: [-9_223_372_036_854_775_808..9_223_372_036_854_775_807] | <<_::128>>, rdev: -2_147_483_648..2_147_483_647, size: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, uid: 0..4_294_967_295 } | [ atimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, birthtimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, blksize: -2_147_483_648..2_147_483_647, blocks: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, ctimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, dev: -2_147_483_648..2_147_483_647, flags: 0..4_294_967_295, gen: 0..4_294_967_295, gid: 0..4_294_967_295, ino: 0..18_446_744_073_709_551_615, lspare: -2_147_483_648..2_147_483_647, mode: 0..65535, mtimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 } | [ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 ] | <<_::128>>, nlink: 0..65535, qspare: [-9_223_372_036_854_775_808..9_223_372_036_854_775_807] | <<_::128>>, rdev: -2_147_483_648..2_147_483_647, size: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, uid: 0..4_294_967_295 ] | <<_::1152>> ) :: :ok
archive_entry_new()
@spec archive_entry_new() :: reference()
archive_entry_pathname(arg1)
archive_entry_set_pathname(arg1, arg2)
archive_entry_size(arg1)
@spec archive_entry_size(reference()) :: -9_223_372_036_854_775_808..9_223_372_036_854_775_807
archive_entry_stat(arg1)
@spec archive_entry_stat(reference()) :: %{ atimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 }, birthtimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 }, blksize: -2_147_483_648..2_147_483_647, blocks: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, ctimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 }, dev: -2_147_483_648..2_147_483_647, flags: 0..4_294_967_295, gen: 0..4_294_967_295, gid: 0..4_294_967_295, ino: 0..18_446_744_073_709_551_615, lspare: -2_147_483_648..2_147_483_647, mode: 0..65535, mtimespec: %{ tv_nsec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, tv_sec: -9_223_372_036_854_775_808..9_223_372_036_854_775_807 }, nlink: 0..65535, qspare: [-9_223_372_036_854_775_808..9_223_372_036_854_775_807], rdev: -2_147_483_648..2_147_483_647, size: -9_223_372_036_854_775_808..9_223_372_036_854_775_807, uid: 0..4_294_967_295 }
archive_error_string(arg1)
archive_file_count(arg1)
@spec archive_file_count(reference()) :: -2_147_483_648..2_147_483_647
archive_format(arg1)
@spec archive_format(reference()) :: -2_147_483_648..2_147_483_647
archive_format_name(arg1)
archive_liblz4_version()
@spec archive_liblz4_version() :: binary()
archive_liblzma_version()
@spec archive_liblzma_version() :: binary()
archive_libzstd_version()
@spec archive_libzstd_version() :: binary()
archive_read_close(arg1)
@spec archive_read_close(reference()) :: :ok
archive_read_data(arg1, arg2)
archive_read_extract(arg1, arg2, arg3)
archive_read_format_capabilities(arg1)
@spec archive_read_format_capabilities(reference()) :: -2_147_483_648..2_147_483_647
archive_read_new()
@spec archive_read_new() :: reference()
archive_read_next_header(arg1, arg2)
archive_read_open_filename(arg1, arg2, arg3)
archive_read_open_memory(arg1, arg2)
archive_read_refresh(arg1)
@spec archive_read_refresh(reference()) :: :ok
archive_read_support_compression_all(arg1)
@spec archive_read_support_compression_all(reference()) :: :ok
archive_read_support_filter_all(arg1)
@spec archive_read_support_filter_all(reference()) :: :ok
archive_read_support_filter_by_code(arg1, arg2)
@spec archive_read_support_filter_by_code(reference(), -2_147_483_648..2_147_483_647) :: :ok
archive_read_support_format_all(arg1)
@spec archive_read_support_format_all(reference()) :: :ok
archive_read_support_format_by_code(arg1, arg2)
@spec archive_read_support_format_by_code(reference(), -2_147_483_648..2_147_483_647) :: :ok
archive_read_support_format_raw(arg1)
@spec archive_read_support_format_raw(reference()) :: :ok
archive_version_details()
@spec archive_version_details() :: binary()
archive_version_string()
@spec archive_version_string() :: binary()
archive_write_add_filter(arg1, arg2)
@spec archive_write_add_filter(reference(), -2_147_483_648..2_147_483_647) :: :ok
archive_write_close(arg1)
@spec archive_write_close(reference()) :: :ok
archive_write_header(arg1, arg2)
archive_write_new()
@spec archive_write_new() :: reference()
archive_write_open_filename(arg1, arg2)
archive_write_refresh(arg1)
@spec archive_write_refresh(reference()) :: :ok
archive_write_set_format(arg1, arg2)
@spec archive_write_set_format(reference(), -2_147_483_648..2_147_483_647) :: :ok
archive_zlib_version()
@spec archive_zlib_version() :: binary()
archiveFilterToAtom(arg1)
@spec archiveFilterToAtom(-2_147_483_648..2_147_483_647) ::
:zstd
| :xz
| :uu
| :rpm
| :program
| :none
| :lzop
| :lzma
| :lzip
| :lz4
| :lrzip
| :gzip
| :grzip
| :compress
| :bzip2
archiveFilterToInt(arg1)
@spec archiveFilterToInt(
:zstd
| :xz
| :uu
| :rpm
| :program
| :none
| :lzop
| :lzma
| :lzip
| :lz4
| :lrzip
| :gzip
| :grzip
| :compress
| :bzip2
| 0..14
) :: -2_147_483_648..2_147_483_647
archiveFormatToAtom(arg1)
@spec archiveFormatToAtom(-2_147_483_648..2_147_483_647) ::
:zip
| :xar
| :warc
| :tar_ustar
| :tar_pax_restricted
| :tar_pax_interchange
| :tar_gnutar
| :tar
| :shar_dump
| :shar_base
| :shar
| :sevenz
| :raw
| :rar_v5
| :rar
| :mtree
| :lha
| :iso9660_rockridge
| :iso9660
| :empty
| :cpio_svr4_nocrc
| :cpio_svr4_crc
| :cpio_pwb
| :cpio_posix
| :cpio_bin_le
| :cpio_bin_be
| :cpio_afio_large
| :cpio
| :cab
| :ar_gnu
| :ar_bsd
| :ar
archiveFormatToInt(arg1)
@spec archiveFormatToInt(
:zip
| :xar
| :warc
| :tar_ustar
| :tar_pax_restricted
| :tar_pax_interchange
| :tar_gnutar
| :tar
| :shar_dump
| :shar_base
| :shar
| :sevenz
| :raw
| :rar_v5
| :rar
| :mtree
| :lha
| :iso9660_rockridge
| :iso9660
| :empty
| :cpio_svr4_nocrc
| :cpio_svr4_crc
| :cpio_pwb
| :cpio_posix
| :cpio_bin_le
| :cpio_bin_be
| :cpio_afio_large
| :cpio
| :cab
| :ar_gnu
| :ar_bsd
| :ar
| 1_048_576
| 983_040
| 917_504
| 851_968
| 786_432
| 720_896
| 655_360
| 589_824
| 524_288
| 458_752..458_754
| 393_216
| 327_680
| 262_144..262_145
| 196_608..196_612
| 131_072..131_074
| 65536..65543
) :: -2_147_483_648..2_147_483_647
extractFlagToInt(arg1)
@spec extractFlagToInt(
:xattr
| :unlink
| :time
| :sparse
| :secure_symlinks
| :secure_nodotdot
| :secure_noabsolutepaths
| :safe_writes
| :perm
| :owner
| :no_overwrite_newer
| :no_overwrite
| :no_hfs_compression
| :no_autodir
| :mac_metadata
| :hfs_compression_forced
| :fflags
| :clear_nochange_fflags
| :acl
| 262_144
| 131_072
| 65536
| 32768
| 16384
| 8192
| 4096
| 2048
| 1024
| 512
| 256
| 128
| 64
| 32
| 16
| 8
| 4
| 1..2
) :: -2_147_483_648..2_147_483_647
fileKinds()
@spec fileKinds() :: %{
block_device: 0..4_294_967_295,
character_device: 0..4_294_967_295,
directory: 0..4_294_967_295,
file: 0..4_294_967_295,
mask: 0..4_294_967_295,
named_pipe: 0..4_294_967_295,
sym_link: 0..4_294_967_295,
unix_domain_socket: 0..4_294_967_295,
unknown: 0..4_294_967_295
}
get_error_string(ref)
getExtractInfo()
@spec getExtractInfo() :: [ %{ default_doc: binary(), flag: :xattr | :unlink | :time | :sparse | :secure_symlinks | :secure_nodotdot | :secure_noabsolutepaths | :safe_writes | :perm | :owner | :no_overwrite_newer | :no_overwrite | :no_hfs_compression | :no_autodir | :mac_metadata | :hfs_compression_forced | :fflags | :clear_nochange_fflags | :acl } ]
isSubFormatOf(arg1, arg2)
@spec isSubFormatOf( :zip | :xar | :warc | :tar_ustar | :tar_pax_restricted | :tar_pax_interchange | :tar_gnutar | :tar | :shar_dump | :shar_base | :shar | :sevenz | :raw | :rar_v5 | :rar | :mtree | :lha | :iso9660_rockridge | :iso9660 | :empty | :cpio_svr4_nocrc | :cpio_svr4_crc | :cpio_pwb | :cpio_posix | :cpio_bin_le | :cpio_bin_be | :cpio_afio_large | :cpio | :cab | :ar_gnu | :ar_bsd | :ar | 1_048_576 | 983_040 | 917_504 | 851_968 | 786_432 | 720_896 | 655_360 | 589_824 | 524_288 | 458_752..458_754 | 393_216 | 327_680 | 262_144..262_145 | 196_608..196_612 | 131_072..131_074 | 65536..65543, :zip | :xar | :warc | :tar_ustar | :tar_pax_restricted | :tar_pax_interchange | :tar_gnutar | :tar | :shar_dump | :shar_base | :shar | :sevenz | :raw | :rar_v5 | :rar | :mtree | :lha | :iso9660_rockridge | :iso9660 | :empty | :cpio_svr4_nocrc | :cpio_svr4_crc | :cpio_pwb | :cpio_posix | :cpio_bin_le | :cpio_bin_be | :cpio_afio_large | :cpio | :cab | :ar_gnu | :ar_bsd | :ar | 1_048_576 | 983_040 | 917_504 | 851_968 | 786_432 | 720_896 | 655_360 | 589_824 | 524_288 | 458_752..458_754 | 393_216 | 327_680 | 262_144..262_145 | 196_608..196_612 | 131_072..131_074 | 65536..65543 ) :: boolean()
list_all(atom1, atom2)
listReadableFilters()
@spec listReadableFilters() :: [binary()]
listReadableFormats()
@spec listReadableFormats() :: [binary()]
listWritableFilters()
@spec listWritableFilters() :: [binary()]
listWritableFormats()
@spec listWritableFormats() :: [binary()]