Skip to content

tar

Streams TAR archives with optional gzip or zstd compression.

Types

Type Description
Reader Destructive archive entry iterator
Entry Metadata and content for one entry
Writer Sequential archive writer
EntryWriter Scoped entry content sink

Functions

read path func

Opens an archive and calls func with a Reader. Compression is detected from gzip or zstd magic bytes.

Parameters:

Name Type Description
path Str|Path Archive path
func callable Reader scope

Returns: the result of func.

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

write path :compression? func

Creates an archive and calls func with a Writer.

Parameters:

Name Type Description
path Str|Path Archive path
compression Sym? :NONE:, :GZIP:, or :ZSTD:
func callable Writer scope

When compression is 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.

Returns: the result of func.

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