// //------------------ DOK FILE -------------------------------------------------- +Header compressLib =pkg bios =title Compressions =short deflate and lzw =desc Minimacy embeds two compression algorithms: Lzw and deflate. Lzw is used in gif files, deflate is used in zip, gzip and png files. // // //------------------ PROTO ----------------------------------------------------- strFromLzw +Proto strFromLzw =type fun Str Int -> Str =mode function =pkg bios =impl mcy =link =desc This function inflates a compressed string and returns the original data or nil if the data is corrupted. bitLen defines the size of the internal directory which is always a power of 2. Default value is 8 when nBits is zero or nil: then the internal directory is 2^8=256. // +arg data =type Str =desc A string // +arg bitLen =type Int =desc A positive integer or nil // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- lzwFromStr +Proto lzwFromStr =type fun Str Int -> Str =mode function =pkg bios =impl mcy =link =desc This function deflates a string and returns the compressed data. bitLen defines the size of the internal directory which is always a power of 2. Default value is 8 when nBits is zero or nil: then the internal directory is 2^8=256. // +arg data =type Str =desc A string // +arg bitLen =type Int =desc A positive integer or nil // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- inflate +Proto inflate =type fun Str -> Str =mode function =pkg bios =impl mcy =link =desc This function inflates a compressed data. This function returns nil when the compressed data is corrupted. // +arg data =type Str =desc A compressed string // +arg result =type Str =desc The original string // // //------------------ PROTO ----------------------------------------------------- deflate +Proto deflate =type fun Str -> Str =mode function =pkg bios =impl mcy =link =desc This function deflates (compresses) a data. The original data can be recovered by applying [[inflate]] to the compressed string. For now this [[deflate]] implementation produces only dynamic Huffman codes blocks, without LZ77 optimization. // +arg data =type Str =desc Any string // +arg result =type Str =desc The compressed string // // //------------------ PROTO ----------------------------------------------------- deflateBytes +Proto deflateBytes =type fun Bytes -> Str =mode function =pkg bios =impl mcy =link =desc This function deflates (compresses) a data. The original data can be recovered by applying [[inflate]] to the compressed string. For now this [[deflate]] implementation produces only dynamic Huffman codes blocks, without LZ77 optimization. // +arg data =type Bytes =desc A string provided as an array of bytes // +arg result =type Str =desc The compressed string