0 | module Codec.Compression.Zlib.Types
 1 |
 2 | import Data.Buffer.Core
 3 | import System.Zlib.Types
 4 |
 5 | %default total
 6 |
 7 | --------------------------------------------------------------------------------
 8 | --          Compresssor/Decompressor
 9 | --------------------------------------------------------------------------------
10 |
11 | ||| Represents an initialized zlib compression stream owned by the
12 | ||| high-level compression API.
13 | |||
14 | ||| A `Compressor` is created only after zlib has successfully initialized
15 | ||| the underlying stream. It must therefore eventually be finalized with
16 | ||| `deflateEnd` and its native stream storage released.
17 | |||
18 | public export
19 | record Compressor where
20 |   constructor MkCompressor
21 |   stream : ZStreamHandle
22 |
23 | ||| Represents an initialized zlib decompression stream owned by the
24 | ||| high-level decompression API.
25 | |||
26 | ||| A `Decompressor` is created only after zlib has successfully initialized
27 | ||| the underlying stream. It must therefore eventually be finalized with
28 | ||| `inflateEnd` and its native stream storage released.
29 | |||
30 | public export
31 | record Decompressor where
32 |   constructor MkDecompressor
33 |   stream : ZStreamHandle
34 |
35 | ||| Describes the progress made by one zlib buffer operation.
36 | |||
37 | ||| `consumed` is the number of input bytes consumed by zlib and `produced`
38 | ||| is the number of bytes written to the supplied output buffer.
39 | |||
40 | public export
41 | record BufferResult where
42 |   constructor MkBufferResult
43 |   status   : Int
44 |   consumed : Nat
45 |   produced : Nat
46 |
47 | --------------------------------------------------------------------------------
48 | --          Streaming
49 | --------------------------------------------------------------------------------
50 |
51 | ||| Result of incrementally compressing input.
52 | |||
53 | ||| `output` contains zero or more compressed chunks generated while consuming
54 | ||| the supplied input.
55 | |||
56 | ||| `finished` is true only after zlib has returned `Z_STREAM_END`.
57 | |||
58 | public export
59 | record CompressStreamResult where
60 |   constructor MkCompressStreamResult
61 |   consumed : Nat
62 |   output   : List AnyBuffer
63 |   finished : Bool
64 |
65 | ||| Result of incrementally decompressing input.
66 | |||
67 | ||| `consumed` is the number of bytes consumed from the supplied input buffer.
68 | ||| This can be less than the input size when `Z_STREAM_END` is reached, allowing
69 | ||| the caller to retain trailing bytes or begin processing another stream.
70 | |||
71 | ||| `output` contains zero or more decompressed chunks.
72 | |||
73 | ||| `finished` is true when zlib returned `Z_STREAM_END`.
74 | |||
75 | public export
76 | record DecompressStreamResult where
77 |   constructor MkDecompressStreamResult
78 |   consumed : Nat
79 |   output   : List AnyBuffer
80 |   finished : Bool
81 |