Compress

The Compress module provides functions for data compression and decompression using Gzip, Zlib, and raw Deflate algorithms, plus checksum functions.

Gzip

Functions for Gzip compression, commonly used for HTTP compression and .gz files.

Gzip.compress
String -> Int -> Result String String
Compresses data using gzip format. The second argument is the compression level (1-9, where 9 is maximum compression).
match Gzip.compress "Hello, World!" 6
  | Ok compressed -> println "Compressed ${String.length compressed} bytes"
  | Err e -> println "Error: ${e}"
Gzip.decompress
String -> Result String String
Decompresses gzip-compressed data.
match Gzip.decompress compressed-data
  | Ok original -> println original
  | Err e -> println "Error: ${e}"
Gzip.compress-file
String -> String -> Result () String
Compresses a file to gzip format. Takes source path and destination path.
match Gzip.compress-file "data.txt" "data.txt.gz"
  | Ok _ -> println "File compressed"
  | Err e -> println "Error: ${e}"
Gzip.decompress-file
String -> String -> Result () String
Decompresses a gzip file. Takes source path and destination path.
match Gzip.decompress-file "data.txt.gz" "data.txt"
  | Ok _ -> println "File decompressed"
  | Err e -> println "Error: ${e}"
Gzip.is-gzip?
String -> Bool
Returns true if the data appears to be gzip-compressed (checks magic bytes).

Zlib

Functions for Zlib compression, commonly used in PNG images and many network protocols.

Zlib.compress
String -> Int -> Result String String
Compresses data using zlib format. The second argument is the compression level (1-9).
match Zlib.compress "Hello, World!" 6
  | Ok compressed -> println "Compressed to ${String.length compressed} bytes"
  | Err e -> println "Error: ${e}"
Zlib.decompress
String -> Result String String
Decompresses zlib-compressed data.
Zlib.is-zlib?
String -> Bool
Returns true if the data appears to be zlib-compressed.

Deflate

Functions for raw Deflate compression without headers.

Deflate.compress
String -> Int -> Result String String
Compresses data using raw deflate (no gzip/zlib headers). The second argument is the compression level (1-9).
Deflate.decompress
String -> Result String String
Decompresses raw deflate data.

Checksum

Functions for computing checksums for data integrity verification.

Checksum.crc32
String -> Int
Computes the CRC32 checksum of the data. Returns a 32-bit integer.
checksum = Checksum.crc32 "Hello, World!"
println "CRC32: ${Int.to-hex checksum}"
Checksum.adler32
String -> Int
Computes the Adler-32 checksum of the data. Faster than CRC32 but slightly less reliable for error detection.
checksum = Checksum.adler32 "Hello, World!"
println "Adler32: ${checksum}"