Skip to content

tar

Streams TAR archives with optional gzip or zstd compression.

Types

TypeDescription
Entry Metadata and streaming content for the current TAR entry.
EntryWriter Content sink for one scoped TAR entry.
Reader Destructive iterator over the entries in an open TAR archive.
Writer Sequential writer for a new TAR archive.

Functions

read[R] path func -> R

Opens an archive and calls func with a Reader.

Compression is detected from gzip or zstd magic bytes.

Parameters

NameTypeDescription
path (Str | fs.Path) Archive path.
func ((Reader) -> R) Reader scope, called with a Reader.

Example

read "archive.tar.gz" do |archive|
  for entry = archive
    echo "$entry.path: $entry.size bytes"

write[R] path func … -> R

Creates an archive and calls func with a Writer.

Parameters

NameTypeDescription
path (Str | fs.Path) Archive path.
:compression? (:NONE: | :GZIP: | :ZSTD:) Compression.
func ((Writer) -> R) Writer scope, called with a Writer.
:compression

When omitted, .gz and .tgz select gzip, .zst and .tzst select zstd, and other extensions select no compression. Extension matching is case-insensitive. An explicit compression overrides the path.

Example

write "archive.tar.zst" do |archive|
  archive.entry greeting.txt size: 5 do |entry|
    entry.write hello