package zipc

  1. Overview
  2. Docs

Archive file data.

File data

type t

The type for file data.

val make : ?version_made_by:Zipc_deflate.uint16 -> ?version_needed_to_extract:Zipc_deflate.uint16 -> ?gp_flags:Zipc_deflate.uint16 -> ?start:int -> ?compressed_size:int -> compression:compression -> string -> decompressed_size:int -> decompressed_crc_32:Zipc_deflate.Crc_32.t -> (t, string) result

make creates file data with given properties, see their corresponding accessors for details. The defaults are:

  • start defaults to 0.
  • compressed_size defaults to the string's length minus start.
  • version_made_by defaults to 0x314 indicating UNIX (for encoding file permissions) and PKZIP 2.0.
  • version_needed_to_extract defaults to 20 indicating PKZIP 2.0. This may need tweaking depending on compression but decoders likely do not care (see 4.4.3.2 in the specification).
  • gp_flags defaults to 0x800, indicating UTF-8 encoded filenames.

Error _ is returned with a suitable error message if any of the given length exceeds 4294967295, see max_size. Negative lengths raise Invalid_argument.

val stored_of_binary_string : ?start:int -> ?len:int -> string -> (t, string) result

stored_of_binary_string s is s as Stored (no compression) file data. This errors if s exceeds max_size. start defaults to 0 and len to String.length s - start.

val deflate_of_binary_string : ?level:Zipc_deflate.level -> ?start:int -> ?len:int -> string -> (t, string) result

deflate_of_binary_string s deflates s and returns it as Deflate file data. level defaults to `Default. This errors if s or its compressed size exceeds max_size. start defaults to 0 and len to String.length s - start.

Properties

val compression : t -> compression

compression file is the compression format of file.

val start : t -> int

start file is the start index in compressed_bytes.

val compressed_size : t -> int

compressed_size file is the byte size in compressed_bytes.

val compressed_bytes : t -> string

compressed_bytes file are the bytes of file in compression format, in the range defined by start and compressed_size.

val compressed_bytes_to_binary_string : t -> string

compressed_bytes_to_binary_string file is the range of compressed_bytes as a tight string.

val decompressed_size : t -> int

decompressed_size file is metadata indicating the size in bytes of the decompressed data of file.

val decompressed_crc_32 : t -> Zipc_deflate.Crc_32.t

decompressed_crc_32 file is metadata indicating the CRC-32 checksum of the decompressed data of file.

val version_made_by : t -> Zipc_deflate.uint16

version_made_by file is the version made by field of file. Not really interested but we keep it to be able to update archives without loosing too much information.

val version_needed_to_extract : t -> Zipc_deflate.uint16

version_needed_to_extract file is the version needed to extract field. See version_made_by.

val gp_flags : t -> Zipc_deflate.uint16

gp_flags file is the general purpose bit flag field of file. In particular it tells us whether the file is_encrypted.

Predicates

val is_encrypted : t -> bool

is_encrypted file is true iff file is encrypted. Zipc has no support for file encryption.

val can_extract : t -> bool

can_extract file is true iff Zipc knows how to extract the bytes of file. In other words if file is not encrypted and its compression is either Stored or Deflate.

Decompressing

val to_binary_string : t -> (string, string) result

to_binary_string file is the decompressed data of file. This only supports Stored or Deflate formats and errors if:

val to_binary_string_no_crc_check : t -> (string * Zipc_deflate.Crc_32.t, string) result

to_binary_string_no_crc_check is like to_binary_string except it does not check the CRC-32 of the decompressed data against decompressed_crc_32, it returns it along with the data.

Limits

val max_size : int

max_size is the maximal file size representable on this platform in the file metadata. This is the minimum between Int.max_int and 4294967295 (4Go), the maximum file size in non-ZIP64 ZIP archives. Archives that have members whose size exceeds this value error on Zipc.of_binary_string.

OCaml

Innovation. Community. Security.