6 | --------------------------------------------------------------------------------
7 | -- Stream Allocation
8 | --------------------------------------------------------------------------------
10 | ||| Allocates a new opaque zlib stream handle.
11 | |||
12 | ||| The returned pointer refers to storage owned by the C shim. The stream must
13 | ||| eventually be released with `prim__freeStream`.
14 | |||
15 | ||| This function only allocates the stream structure; it does not initialize
16 | ||| the stream for compression or decompression.
17 | |||
21 | ||| Releases an opaque zlib stream handle previously allocated with
22 | ||| `prim__newStream`.
23 | |||
24 | ||| Any initialized compression or decompression state must first be finalized
25 | ||| with `prim__deflateEnd` or `prim__inflateEnd`, respectively.
26 | |||
30 | --------------------------------------------------------------------------------
31 | -- Library Information
32 | --------------------------------------------------------------------------------
34 | ||| Returns the version string of the zlib implementation linked by the
35 | ||| `zlib-idris` C shim.
36 | |||
40 | --------------------------------------------------------------------------------
41 | -- Compression
42 | --------------------------------------------------------------------------------
44 | ||| Initializes an opaque stream for compression using zlib's default method,
45 | ||| window size, memory level, and compression strategy.
46 | |||
47 | ||| The supplied integer is a zlib compression level, such as
48 | ||| `Z_DEFAULT_COMPRESSION`.
49 | |||
50 | ||| Unlike zlib's `deflateInit_`, the zlib version and `z_stream` structure
51 | ||| size are supplied by the C shim, preventing ABI-sensitive details from
52 | ||| crossing the Idris FFI boundary.
53 | |||
57 | ||| Initializes an opaque stream for compression with explicit zlib
58 | ||| configuration.
59 | |||
60 | ||| The arguments following the stream are, in order:
61 | |||
62 | ||| - compression level
63 | ||| - compression method
64 | ||| - window bits
65 | ||| - memory level
66 | ||| - compression strategy
67 | |||
68 | ||| The C shim supplies `ZLIB_VERSION` and `sizeof(z_stream)` directly when
69 | ||| invoking `deflateInit2`, keeping those ABI details out of Idris.
70 | |||
74 | ||| Compresses bytes from an Idris `Buffer` into another Idris `Buffer`.
75 | |||
77 | prim__deflateBuffer : AnyPtr -> Buffer -> Bits32 -> Bits32 -> Buffer -> Bits32 -> Bits32 -> Int -> PrimIO Int
79 | ||| Releases all zlib resources associated with an initialized compression
80 | ||| stream.
81 | |||
82 | ||| This does not free the opaque stream handle itself. Call
83 | ||| `prim__freeStream` afterwards to release that storage.
84 | |||
88 | ||| Resets an initialized compression stream while preserving its allocated
89 | ||| zlib state so that it can be reused for another compression operation.
90 | |||
94 | ||| Return an upper bound on the output capacity required to compress the
95 | ||| supplied number of input bytes using an initialized deflate stream.
96 | |||
97 | ||| `UINT64_MAX` is returned by the C shim when the input size or resulting
98 | ||| bound cannot be represented safely by the one-shot zlib buffer interface.
99 | |||
103 | --------------------------------------------------------------------------------
104 | -- Decompression
105 | --------------------------------------------------------------------------------
107 | ||| Initializes an opaque stream for decompression using the standard zlib
108 | ||| wrapper format.
109 | |||
110 | ||| `ZLIB_VERSION` and `sizeof(z_stream)` are supplied by the C shim rather
111 | ||| than crossing the Idris FFI boundary.
112 | |||
116 | ||| Initializes an opaque stream for decompression with explicit `windowBits`.
117 | |||
118 | ||| This is used to select standard zlib, gzip, or raw DEFLATE streams.
119 | ||| `ZLIB_VERSION` and `sizeof(z_stream)` are supplied by the C shim.
120 | |||
124 | ||| Decompresses bytes from an Idris `Buffer` into another Idris `Buffer`.
125 | |||
127 | prim__inflateBuffer : AnyPtr -> Buffer -> Bits32 -> Bits32 -> Buffer -> Bits32 -> Bits32 -> Int -> PrimIO Int
129 | ||| Releases all zlib resources associated with an initialized decompression
130 | ||| stream.
131 | |||
132 | ||| This does not free the opaque stream handle itself. Call
133 | ||| `prim__freeStream` afterwards to release that storage.
134 | |||
138 | ||| Resets an initialized decompression stream while retaining its allocated
139 | ||| zlib state so that it can be reused.
140 | |||
141 | export
145 | --------------------------------------------------------------------------------
146 | -- Buffer Progress
147 | --------------------------------------------------------------------------------
149 | ||| Returns the number of input bytes consumed by the most recent
150 | ||| `prim__deflateBuffer` or `prim__inflateBuffer` call.
151 | |||
155 | ||| Returns the number of output bytes produced by the most recent
156 | ||| `prim__deflateBuffer` or `prim__inflateBuffer` call.
157 | |||
161 | --------------------------------------------------------------------------------
162 | -- Checksums
163 | --------------------------------------------------------------------------------
165 | ||| Update a CRC-32 checksum using the contents of an Idris `Buffer`.
166 | |||
167 | ||| The checksum value and result are represented as fixed-width 32-bit
168 | ||| values even on platforms where zlib's `uLong` is wider.
169 | |||
173 | ||| Update an Adler-32 checksum using the contents of an Idris `Buffer`.
174 | |||
175 | ||| The checksum value and result are represented as fixed-width 32-bit
176 | ||| values even on platforms where zlib's `uLong` is wider.
177 | |||