star
Gleam bindings for Erlang’s erl_tar
to create, extract, and list tar archives with optional gzip compression.
Archives can be read from a file or from an in-memory BitArray
(see ArchiveSource), but building is file-only.
Types
Where to read an archive from.
pub type ArchiveSource {
FromFile(path: String)
FromData(contents: BitArray)
}
Constructors
-
FromFile(path: String)Read the archive from a file at
path. -
FromData(contents: BitArray)Read the archive from an in-memory bit array.
Whether an archive is plain or gzipped.
pub type Compression {
Uncompressed
Gzip
}
Constructors
-
UncompressedPlain, uncompressed tar (
.tar). -
GzipGzip-compressed tar (
.tar.gz).
The kind of entry represented by a tar header.
pub type EntryType {
Regular
HardLink
Symlink
CharDevice
BlockDevice
Directory
Fifo
Unknown(tag: String)
}
Constructors
-
RegularOrdinary file with byte contents.
-
HardLinkHard link to another entry within the archive.
-
SymlinkSymbolic link.
listreports the header (withsize == 0), but the link target is not surfaced.extract_memoryomits symlink entries entirely; useextractto reproduce them on disk. -
CharDeviceCharacter special device.
-
BlockDeviceBlock special device.
-
DirectoryDirectory entry with no contents.
-
FifoNamed pipe (FIFO).
-
Unknown(tag: String)Type flag
erl_tarreported thatstardoes not recognise.
Error returned from any star operation.
pub type Error {
BadHeader
UnexpectedEof
FileNotFound(path: String)
PermissionDenied(path: String)
Unsupported(reason: String)
Other(message: String)
}
Constructors
-
BadHeaderArchive contains a malformed header block.
-
UnexpectedEofArchive stream ended before a complete entry was read.
-
FileNotFound(path: String)Referenced path does not exist on disk.
-
PermissionDenied(path: String)Operating system denied access to the given path.
-
Unsupported(reason: String)Encountered a tar feature
stardoes not handle;reasonechoes the underlying tag. -
Other(message: String)Catch-all for
erl_tarerrors that do not map to a specific variant;messageis the formatted human-readable description.
Which entries an extract or list call should act on.
pub type Filter {
AllEntries
Only(names: List(String))
}
Constructors
-
AllEntriesAct on every entry in the archive.
-
Only(names: List(String))Act only on entries whose
nameappears in the list; names missing from the archive are ignored.
Metadata for an archive entry.
pub type Header {
Header(
name: String,
entry_type: EntryType,
size: Int,
mtime: Int,
mode: Int,
uid: Int,
gid: Int,
)
}
Constructors
-
Header( name: String, entry_type: EntryType, size: Int, mtime: Int, mode: Int, uid: Int, gid: Int, )Arguments
- name
-
Name of the entry as stored in the archive.
- entry_type
-
Kind of entry (regular file, directory, symlink, etc.).
- size
-
Size of the contents in bytes.
- mtime
-
Modification time as Unix epoch seconds.
- mode
-
Unix permission bits, e.g.
0o644. - uid
-
Numeric user id of the entry’s owner.
- gid
-
Numeric group id of the entry’s owner.
What extract should do when an entry would land on a path that
already exists on disk.
pub type OnConflict {
Overwrite
Skip
}
Constructors
-
OverwriteReplace the existing file with the archive entry.
-
SkipLeave the existing file alone and continue extracting other entries.
Values
pub fn add_disk_mapped(
builder: Builder,
at archive_path: String,
from disk_path: String,
) -> Builder
Stage a file on disk under a different name in the archive.
pub fn add_disk_path(
builder: Builder,
from path: String,
) -> Builder
Stage a file on disk. The provided path is used verbatim as both the source path on disk and the entry name in the archive; pass a relative path unless you want absolute paths embedded in the archive. The file’s real on-disk type (regular file, directory, symlink, etc.) is preserved.
pub fn add_file(
builder: Builder,
at path: String,
containing contents: BitArray,
) -> Builder
Stage an in-memory file entry with mode 0o644.
pub fn build_file(
builder: Builder,
at path: String,
compression compression: Compression,
) -> Result(Nil, Error)
Finalise the builder into a tar archive written to path.
pub fn extract(
from source: ArchiveSource,
to path: String,
compression compression: Compression,
filter filter: Filter,
on_conflict on_conflict: OnConflict,
) -> Result(Nil, Error)
Extract every entry (or a filtered subset) from an archive onto disk
under path. on_conflict decides what happens when an entry would
land on a path that already exists.
pub fn extract_memory(
from source: ArchiveSource,
compression compression: Compression,
filter filter: Filter,
) -> Result(List(Entry), Error)
Extract entries from an archive into an in-memory list of Entry
values, in archive order. Non-regular entries (symlinks, hard links,
devices, fifos, directories) are omitted from the result; use
extract to reproduce them on disk, or list to see their headers.
The archive is parsed twice (once for contents, once for headers), so
gzipped sources are decoded twice. Prefer extract for large archives.
pub fn follow_symlinks(
builder: Builder,
enabled: Bool,
) -> Builder
When True, symlinks encountered by add_disk_path or
add_disk_mapped are archived as their target contents rather than as
link entries. Defaults to False.
pub fn list(
from source: ArchiveSource,
compression compression: Compression,
filter filter: Filter,
) -> Result(List(Header), Error)
List the headers of every entry in an archive, optionally filtered to a subset of names.