folkertdev / elm-tiny-inflate / Inflate

Decompress data compressed with a deflate algorithm.

import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as Decode
import Bytes.Encode as Encode
import Inflate

{-| Some sample text
-}
text : String
text =
    "Myn geast ferdizet"

{-| The `text` compressed with raw deflate

The bytes are combined into 32bit integers using
hex notation so they are shorter in the docs

-}
textCompressedBytes =
    [ 0xF3ADCC53
    , 0x484F4D2C
    , 0x2E51484B
    , 0x2D4AC9AC
    , 0x4A2D0100
    ]
        |> List.map (Encode.unsignedInt32 BE)
        |> Encode.sequence
        |> Encode.encode

decodeString : Bytes -> Maybe String
decodeString buffer =
    let
        decoder =
            Decode.string (Encode.getStringWidth text)
    in
    Decode.decode decoder buffer

decompressed =
    textCompressedBytes
        |> Inflate.inflate
        |> Maybe.andThen decodeString
        |> Maybe.withDefault ""

Inflate

inflate : Bytes -> Maybe Bytes

Inflate a sequence of bytes that is compressed with raw deflate.

inflateZLib : Bytes -> Maybe Bytes

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.

inflateGZip : Bytes -> Maybe Bytes

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.

Checksums

crc32 : Bytes -> Basics.Int

The crc32 checksum.

Used in gzip. Slower than adler32, but also more reliable (smaller chance of collisions).

adler32 : Bytes -> Basics.Int

The adler32 checksum.

Used in zlib. Faster than crc32, but also less reliable (larger chance of collisions).