Compress
The Compress module provides functions for data compression and decompression using Gzip, Zlib, and raw Deflate algorithms, plus checksum functions.
In-memory compression helpers do not require authority. File helpers such as
Gzip.compress-file, Zlib.compress-file, and
Deflate.compress-file require FileReadAuth for the input and
FileWriteAuth for the output.
Gzip
Functions for Gzip compression, commonly used for HTTP compression and .gz files.
match Gzip.compress "Hello, World!" 6
| Ok compressed -> println "Compressed ${String.length compressed} bytes"
| Err e -> println "Error: ${e}"
match Gzip.decompress compressed-data
| Ok original -> println original
| Err e -> println "Error: ${e}"
match Gzip.compress-file read-auth write-auth "data.txt" "data.txt.gz" 6
| Ok _ -> println "File compressed"
| Err e -> println "Error: ${e}"
match Gzip.decompress-file read-auth write-auth "data.txt.gz" "data.txt"
| Ok _ -> println "File decompressed"
| Err e -> println "Error: ${e}"
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.
match Zlib.compress "Hello, World!" 6
| Ok compressed -> println "Compressed to ${String.length compressed} bytes"
| Err e -> println "Error: ${e}"
match Zlib.compress-file read-auth write-auth "data.bin" "data.bin.z" 6
| Ok _ -> println "File compressed"
| Err e -> println "Error: ${e}"
match Zlib.decompress-file read-auth write-auth "data.bin.z" "data.bin"
| Ok _ -> println "File decompressed"
| Err e -> println "Error: ${e}"
true if the data appears to be zlib-compressed.
Deflate
Functions for raw Deflate compression without headers.
match Deflate.compress-file read-auth write-auth "data.bin" "data.bin.deflate" 6
| Ok _ -> println "File compressed"
| Err e -> println "Error: ${e}"
match Deflate.decompress-file read-auth write-auth "data.bin.deflate" "data.bin"
| Ok _ -> println "File decompressed"
| Err e -> println "Error: ${e}"
Checksum
Functions for computing checksums for data integrity verification.
checksum = Checksum.crc32 "Hello, World!"
println "CRC32: ${Int.to-hex checksum}"
checksum = Checksum.adler32 "Hello, World!"
println "Adler32: ${checksum}"