Skip to content

zip

Reads and writes ZIP archives.

The API is VFS-transparent: archive paths use the active VFS context.

Types

TypeDescription
Archive An open ZIP archive.
Entry A single archive entry's metadata, with a method to open it for reading.
File An open file within a ZIP archive.
OpenMode Access mode accepted by open.

OpenMode = ("r" | "w")

Access mode accepted by open.

Mode Description
"r" Read mode -- opens an existing archive for reading
"w" Write mode -- creates a new archive, truncating any existing one

Functions

open path … -> Archive

Opens a ZIP archive.

The archive stays open until Archive.close is called.

Parameters

NameTypeDescription
path (Str | fs.Path) Path to the ZIP archive file.
mode? OpenMode Access mode. Defaults to "r".

open[R] path func -> R

Opens a ZIP archive for reading and calls func with it. The archive is closed when func returns.

open "archive.zip" do |archive|
  for entry = archive.entries
    echo "Entry: $entry.name"

Parameters

NameTypeDescription
path (Str | fs.Path) Path to the ZIP archive file.
func ((Archive) -> R) Called with the Archive.

open[R] path mode func -> R

Opens a ZIP archive with a mode and calls func with it. The archive is closed when func returns.

open "output.zip" "w" do |archive|
  archive.open "file.txt" do |file|
    file.write "Hello, World!"

Parameters

NameTypeDescription
path (Str | fs.Path) Path to the ZIP archive file.
mode OpenMode Access mode.
func ((Archive) -> R) Called with the Archive.