Archive

The Archive module provides functions for working with ZIP and TAR archives. Extract, create, and inspect archive contents with a simple functional API.

Zip

Functions for working with ZIP archives.

Zip.extract
String -> String -> Result () String
Extracts a ZIP archive to a destination directory.
match Zip.extract "archive.zip" "./output"
  | Ok _ -> println "Extracted successfully"
  | Err e -> println "Error: ${e}"
Zip.list
String -> Result [ZipEntry] String
Lists entries in a ZIP archive. Returns a list of records with name, size, and compressed-size fields.
match Zip.list "archive.zip"
  | Ok entries -> entries |> each (fn(e) => println e.name)
  | Err e -> println "Error: ${e}"
Zip.count
String -> Result Int String
Returns the number of entries in a ZIP archive.
match Zip.count "archive.zip"
  | Ok n -> println "Archive contains ${n} files"
  | Err e -> println "Error: ${e}"
Zip.total-size
String -> Result Int String
Returns the total uncompressed size of all files in the archive.
Zip.total-compressed-size
String -> Result Int String
Returns the total compressed size of all files in the archive.
Zip.is-zip?
String -> Bool
Returns true if the file appears to be a valid ZIP archive (checks magic bytes).
if Zip.is-zip? "file.zip" then
  println "Valid ZIP file"
else
  println "Not a ZIP file"
Zip.create
String -> [String] -> Result () String
Creates a ZIP archive from a list of file paths.
match Zip.create "output.zip" ["file1.txt", "file2.txt"]
  | Ok _ -> println "Archive created"
  | Err e -> println "Error: ${e}"

Tar

Functions for working with TAR archives, including gzip-compressed variants.

Tar.extract
String -> String -> Result () String
Extracts a TAR archive to a destination directory.
match Tar.extract "archive.tar" "./output"
  | Ok _ -> println "Extracted successfully"
  | Err e -> println "Error: ${e}"
Tar.extract-gz
String -> String -> Result () String
Extracts a gzip-compressed TAR archive (.tar.gz or .tgz) to a destination directory.
match Tar.extract-gz "archive.tar.gz" "./output"
  | Ok _ -> println "Extracted successfully"
  | Err e -> println "Error: ${e}"
Tar.list
String -> Result [TarEntry] String
Lists entries in a TAR archive. Returns a list of records with name, size, and kind fields.
match Tar.list "archive.tar"
  | Ok entries -> entries |> each (fn(e) => println "${e.name} (${e.kind})")
  | Err e -> println "Error: ${e}"
Tar.list-gz
String -> Result [TarEntry] String
Lists entries in a gzip-compressed TAR archive.
Tar.create
String -> [String] -> Result () String
Creates a TAR archive from a list of file paths.
match Tar.create "output.tar" ["file1.txt", "file2.txt"]
  | Ok _ -> println "Archive created"
  | Err e -> println "Error: ${e}"
Tar.count
String -> Result Int String
Returns the number of entries in a TAR archive.
Tar.is-tar?
String -> Bool
Returns true if the file appears to be a valid TAR archive (checks for ustar magic).