An implementation of DEFLATE compression.
The deflate format is used in common file formats like gzip, png, and woff.
import Bytes
import Bytes.Encode as Encode
import Bytes.Decode as Decode
text : String
text =
"Dyn flam dôve nea"
decodeAsString : Bytes -> Maybe String
decodeAsString buffer =
let
decoder = Decode.string (Bytes.width buffer)
in
Decode.decode decoder buffer
inflate (deflate (Encode.encode (Encode.string text)))
|> Maybe.andThen decodeAsString
--> Just "Dyn flam dôve nea"Inflate (decode) data encoded with DEFLATE
Deflate with the gzip format
Note: the gzip header and trailer are not customizable in the current version.
Inflate data compressed with gzip. gzip adds some extra data at the front and the back. This decoder will take care of that and also check the checksum if specified.
Note: this only gives back the inflated data block. The header and trailer parts are discarded, but checksums (if specified) will be checked.
Deflate with the zlib format
Note: the zlib header and trailer are not customizable in the current version.
Inflate data compressed with zlib. zlib adds some extra data at the front and the back. This decoder will take care of that and also check the checksum if specified.
Note: this only gives back the inflated data block. The header and trailer parts are discarded, but checksums (if specified) are checked.
Deflate a sequence of bytes
import LZ77
import Bytes
data : Bytes.Bytes
data =
Encode.encode (Encode.string "foo")
deflateWithOptions Raw data
|> ByteArray.fromBytes
--> Array.fromList [1,3,0,252,-1,102,111,111]
deflateWithOptions (Static NoCompression) data
|> ByteArray.fromBytes
--> Array.fromList [75,203,207,7,0]
deflateWithOptions (Dynamic (WithWindowSize LZ77.maxWindowSize)) data
|> ByteArray.fromBytes
--> Array.fromList [5,192,33,1,0,0,0,128,-96,183,86,254,55,137,1]The type of encoding used
default: Dynamic
The type of compression used
default: WithWindowSize LZ77.maxWindowSize
The adler32 checksum. Used in zlib. Faster than crc32, but also less reliable (larger chance of collisions).
The crc32 checksum. Used in gzip. Slower than adler32, but also more reliable (smaller chance of collisions).
Deflate a sequence of bytes. This is an alias for:
That means good compression, but can be slow for large data. The README elaborates on deflate performance.
deflateWithOptionsallows you to pick different deflate options.