Zipc
ZIP archives.
Consult the quick start and limitations.
References.
The type for compression formats.
Zipc
only handles Stored
and Deflate
but third party libraries can be used to support others formats or to plug an alternate implementation of Deflate
.
val pp_compression : Stdlib.Format.formatter -> compression -> unit
pp_compression
formats compression formats.
module Fpath : sig ... end
File paths and modes.
module Ptime : sig ... end
POSIX time.
module File : sig ... end
Archive file data.
module Member : sig ... end
Archive members.
val empty : t
empty
is an empty archive.
val is_empty : t -> bool
is_empty z
is true
iff z
is empty.
fold f z acc
folds f
over the members of z
starting with acc
in increasing lexicographic member path order. In particular this means that directory members, if they exist, are folded over before any of their content (assuming paths without relative segments).
add member z
is z
with member
added. Overrides a previous member with the same path in z
(if any).
val member_count : t -> int
member_count z
is the number of members in z
.
to_string_map z
is z
as a map from Member.path
to their values.
of_string_map map
is map
as a ZIP archive.
Warning. It is assumed that in map
each key k
maps to a member m
with Member.path m = k
. This is not checked by the function.
string_has_magic s
is true
iff s
has at least 4 bytes and starts with PK\x03\04
or PK\x05\06
(empty archive).
val of_binary_string : string -> (t, string) Stdlib.result
of_binary_string s
decodes a ZIP archive from s
.
Note. ZIP archives's integrity constraints are unclear. For now based on sanity and certain archives found in the wild that are supported by the unzip
tool the following is done:
0
we lookup and use the value found in its local file header.val encoding_size : t -> int
encoding_size z
is the number of bytes needed to encode z
.
to_binary_string z
is the encoding of archive z
. Error _
is returned with a suitable error message in case z
has more members than Member.max
.
If a member with path first
exists in z
then this member's data is written first in the ZIP archive. It defaults to "mimetype"
to support the EPUB OCF ZIP container constraint (you are however in charge of making sure this member is not compressed in this case).
Note.
Member.mtime
that are before the Ptime.dos_epoch
are silently truncated to that date.first
, member data is encoded in the (deterministic) increasing lexical order of their path.File.gp_flags
is always set to 0
on encoding.write_bytes t ~start b
writes to_binary_string
to bytes
starting at start
(defaults to 0
).
Raises Invalid_argument
if b
is too small.
Up to the limitations listed below Zipc
is suitable for the following:
.jar
, .usdz
(mandates no compression), .kmz
, etc. Note that these formats do not always formally restrict the compression formats but deflate seems to be widely used.It is not the aim of Zipc
to be able to read every ZIP archive out there. The format is quite loose, highly denormalized, has plenty of ways to encode metadata and allows many modern and legacy compression algorithms to be used. Hence take into account the following points:
first
in Zipc.to_binary_string
and defaults to "mimetype"
. This supports the EPUB OCF ZIP container constraint which is the only format we are aware of that mandates an ordering in ZIP archives. A more general scheme (e.g. a Zipc.Member.order
property) could be devised would that be needed.of_binary_string
.Sys.max_string_size
.uint32
values in Zip archives but are represented by an OCaml int
in Zipc
. This is not a problem on 64-bit
platforms but can be in on 32-bit platforms and js_of_ocaml
where Int.max_int
is respectively 230-1 and 231-1. See Zipc.File.max_size
for more information.