Archive
The Archive module provides functions for working with ZIP and TAR archives. Extract, create, and inspect archive contents with a simple functional API.
File Capabilities
Archive helpers that read archive files require FileReadAuth. Helpers that extract,
create, or write files also require FileAuth or FileWriteAuth, depending
on the operation.
Zip
Functions for working with ZIP archives.
Zip.extract
FileReadAuth -> FileAuth -> String -> String -> Result () String
Extracts a ZIP archive to a destination directory.
match Zip.extract read-auth file-auth "archive.zip" "./output"
| Ok _ -> println "Extracted successfully"
| Err e -> println "Error: ${e}"
Zip.list
FileReadAuth -> 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 read-auth "archive.zip"
| Ok entries -> entries |> each (fn(e) => println e.name)
| Err e -> println "Error: ${e}"
Zip.count
FileReadAuth -> String -> Result Int String
Returns the number of entries in a ZIP archive.
match Zip.count read-auth "archive.zip"
| Ok n -> println "Archive contains ${n} files"
| Err e -> println "Error: ${e}"
Zip.total-size
FileReadAuth -> String -> Result Int String
Returns the total uncompressed size of all files in the archive.
Zip.total-compressed-size
FileReadAuth -> String -> Result Int String
Returns the total compressed size of all files in the archive.
Zip.is-zip?
FileReadAuth -> String -> Bool
Returns
true if the file appears to be a valid ZIP archive (checks magic bytes).
if Zip.is-zip? read-auth "file.zip" then
println "Valid ZIP file"
else
println "Not a ZIP file"
Zip.create
FileReadAuth -> FileWriteAuth -> String -> [String] -> Result () String
Creates a ZIP archive from a list of file paths.
match Zip.create read-auth write-auth "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
FileReadAuth -> FileAuth -> String -> String -> Result () String
Extracts a TAR archive to a destination directory. Takes read authority for the archive
and full file authority for the extracted files.
match Tar.extract read-auth file-auth "archive.tar" "./output"
| Ok _ -> println "Extracted successfully"
| Err e -> println "Error: ${e}"
Tar.extract-gz
FileReadAuth -> FileAuth -> String -> String -> Result () String
Extracts a gzip-compressed TAR archive (.tar.gz or .tgz) to a destination directory.
Takes read authority for the archive and full file authority for the extracted files.
match Tar.extract-gz read-auth file-auth "archive.tar.gz" "./output"
| Ok _ -> println "Extracted successfully"
| Err e -> println "Error: ${e}"
Tar.list
FileReadAuth -> String -> Result [TarEntry] String
Lists entries in a TAR archive. Requires read authority and returns a list of records
with
name, size, and kind fields.
match Tar.list read-auth "archive.tar"
| Ok entries -> entries |> each (fn(e) => println "${e.name} (${e.kind})")
| Err e -> println "Error: ${e}"
Tar.list-gz
FileReadAuth -> String -> Result [TarEntry] String
Lists entries in a gzip-compressed TAR archive. Requires read authority.
Tar.create
FileReadAuth -> FileWriteAuth -> String -> [String] -> Result () String
Creates a TAR archive from a list of file paths. Takes read authority for the input
files and write authority for the output archive.
match Tar.create read-auth write-auth "output.tar" ["file1.txt", "file2.txt"]
| Ok _ -> println "Archive created"
| Err e -> println "Error: ${e}"
Tar.count
FileReadAuth -> String -> Result Int String
Returns the number of entries in a TAR archive. Requires read authority.
Tar.is-tar?
FileReadAuth -> String -> Bool
Returns
true if the file appears to be a valid TAR archive (checks for ustar magic).
Requires read authority.