package zipc

  1. Overview
  2. Docs

Module Zipc.FileSource

Archive file data.

File data

Sourcetype t

The type for file data.

Sourceval 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.

Sourceval 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.

Sourceval 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

Sourceval compression : t -> compression

compression file is the compression format of file.

Sourceval start : t -> int

start file is the start index in compressed_bytes.

Sourceval compressed_size : t -> int

compressed_size file is the byte size in compressed_bytes.

Sourceval compressed_bytes : t -> string

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

Sourceval compressed_bytes_to_binary_string : t -> string

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

Sourceval decompressed_size : t -> int

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

Sourceval 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.

Sourceval 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.

Sourceval version_needed_to_extract : t -> Zipc_deflate.uint16

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

Sourceval 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

Sourceval is_encrypted : t -> bool

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

Sourceval 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

Sourceval 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:

Sourceval 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

Sourceval 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.