Module Zipc_deflate

Deflate and zlib compressed data formats.

Note. This not needed to use Zipc.

This module provides (non-streaming) support to compress and decompress the deflate (RFC 1951) and zlib (RFC 1950) data formats.

Checksums

type uint16 = int

The type for unsigned 16-bit integers.

type uint32 = int32

The type for unsigned 32-bit integers.

module Crc_32 : sig ... end

ZIP CRC-32 checksums.

module Adler_32 : sig ... end

Adler-32 checksums.

Decompressing

val inflate : ?decompressed_size:int -> ?start:int -> ?len:int -> string -> (string, string) Stdlib.result

inflate s are the decompressed bytes of the deflate compressed data in the range [start;start+len-1] of s. start defaults to 0 and len defaults to String.length s - start. decompressed_size is the expected size of the decompressed data, errors if exceeded.

Returns Error _ with an english error message if the data is corrupted, if the decompressed data exceeds decompressed_size or Sys.max_string_length.

val inflate_and_crc_32 : ?decompressed_size:int -> ?start:int -> ?len:int -> string -> (string * Crc_32.t, string) Stdlib.result

inflate_and_crc_32 is like inflate but also returns the CRC-32 checksum of the output bytes.

val inflate_and_adler_32 : ?decompressed_size:int -> ?start:int -> ?len:int -> string -> (string * Adler_32.t, string) Stdlib.result

inflate_and_crc_32 is like inflate but also returns the Adler-32 checksum of the output bytes.

val zlib_decompress : ?decompressed_size:int -> ?start:int -> ?len:int -> string -> (string * Adler_32.t, (Adler_32.t * Adler_32.t) option * string) Stdlib.result

zlib_decompress s are the decompressed bytes of the zlib compressed data in the range [start;start+len-1] of s. start defaults to 0 and len defaults to String.length s - start. decompressed_size is the expected size of decompressed data, errors if exceeded. The (successfully checked) Adler-32 checksum of the decompressed data is also returned.

Returns Error _ with an english error message if the data is corrupted, if the checksum mismatches (in which case you get the expected and found CRCs in the option, the error message mentions them), if the stream declares a preset dictionary, if the decompressed data exceeds decompressed_size or Sys.max_string_length.

Compression

type level = [
  1. | `None
    (*

    Only non-compressed blocks.

    *)
  2. | `Fast
  3. | `Default
  4. | `Best
]

The type for compression levels.

val deflate : ?level:level -> ?start:int -> ?len:int -> string -> (string, string) Stdlib.result

deflate s is the compressed data in deflate format of the uncompressed bytes stored in the range [start;start+len-1] of s. start defaults to 0 and len defaults to String.length s - start. level defaults to `Default.

Returns Error _ if a string cannot hold the compressed result on 32-bit platforms.

val crc_32_and_deflate : ?level:level -> ?start:int -> ?len:int -> string -> (Crc_32.t * string, string) Stdlib.result

crc_32_and_deflate is like deflate but is also returns the CRC-32 checksum of the input bytes.

val adler_32_and_deflate : ?level:level -> ?start:int -> ?len:int -> string -> (Adler_32.t * string, string) Stdlib.result

adler_32_and_deflate is like deflate but is also returns the Adler-32 checksum of the input bytes.

val zlib_compress : ?level:level -> ?start:int -> ?len:int -> string -> (Adler_32.t * string, string) Stdlib.result

zlib_compress s is the compressed data in zlib format of the uncompressed bytes stored in the range [start;start+len-1] of s. start defaults to 0 and len defaults to String.length s - start. level defaults to `Default. For information the Adler-32 checksum of s is also returned.

Returns Error _ if a string cannot hold the compressed result on 32-bit platforms.