Commit 5fde2245 authored by Ralf Treinen's avatar Ralf Treinen

New upstream version 1.08

parent 0402408b
*.a
*.cma
*.cmi
*.cmo
*.cmx
*.cmxs
*.cmxa
*.o
*.so
test/minigzip
test/minizip
Release 1.08:
- ocamlfind is now mandatory as a consequence of GPR#4
- GPR#4: use ocamlfind and $(EXT_...) configuration variables for better
cross-platform support in Makefile [user 'whitequark']
- Improve Mingw support in Makefile (install .dll files) [Bertrand Jeannet]
- GPR#5: make sure 'zip' and 'camlzip' packages can be used both in the
same executable [Rudi Grinberg]
- GPR#6: Z_BUF_ERROR is not a fatal error, just a transient condition
[Tuukka Korhonen]
- GPR#13: fix memory leak in Zlib.compress_direct [Alain Frisch]
- GPR#14: add Zlib.deflate_string and Zlib.inflate_string, using immutable
strings as input buffers instead of mutable bytes [Vincent Balat]
- GPR#16: assertion failure when reading ZIP files with 2^16 entries or more
[Einar Lielmanis]
- GPR#18: in Zip.open_in, properly close channels in case of error
[Daniel Weil]
Release 1.07:
- Allocate Zlib data structures outside the OCaml heap for compatibility
with recent versions of Zlib
......
version="1.07"
requires="unix"
archive(byte)="zip.cma"
archive(native)="zip.cmxa"
archive(native,plugin)="zip.cmxs"
directory="../zip"
requires="zip"
\ No newline at end of file
version="1.07"
version="1.08"
requires="unix"
archive(byte)="zip.cma"
archive(native)="zip.cmxa"
......
......@@ -13,32 +13,28 @@ ZLIB_LIBDIR=
ZLIB_INCLUDE=
# ZLIB_INCLUDE=/usr/local/include
# Where to install the library. By default: sub-directory 'zip' of
# OCaml's standard library directory.
INSTALLDIR=`$(OCAMLC) -where`/zip
### End of configuration section
OCAMLC=ocamlc -g -safe-string
OCAMLOPT=ocamlopt -safe-string
OCAMLDEP=ocamldep
OCAMLMKLIB=ocamlmklib
OCAMLC=ocamlfind ocamlc -g -safe-string
OCAMLOPT=ocamlfind ocamlopt -safe-string
OCAMLDEP=ocamlfind ocamldep
OCAMLMKLIB=ocamlfind ocamlmklib
OBJS=zlib.cmo zip.cmo gzip.cmo
C_OBJS=zlibstubs.o
NATDYNLINK := $(shell if [ -f `ocamlc -where`/dynlink.cmxa ]; then echo YES; else echo NO; fi)
include $(shell ocamlfind ocamlc -where)/Makefile.config
ifeq "${NATDYNLINK}" "YES"
ifeq "${NATDYNLINK}" "true"
CMXS = zip.cmxs
endif
ZLIB_L_OPT=$(if $(ZLIB_LIBDIR),-L$(ZLIB_LIBDIR))
ZLIB_I_OPT=$(if $(ZLIB_INCLUDE),-ccopt -I$(ZLIB_INCLUDE))
ZLIB_L_OPT=$(if $(ZLIB_LIBDIR),-L$(ZLIB_LIBDIR))
ZLIB_I_OPT=$(if $(ZLIB_INCLUDE),-ccopt -I$(ZLIB_INCLUDE))
all: libcamlzip.a zip.cma
all: libcamlzip$(EXT_LIB) zip.cma
allopt: libcamlzip.a zip.cmxa $(CMXS)
allopt: libcamlzip$(EXT_LIB) zip.cmxa $(CMXS)
zip.cma: $(OBJS)
$(OCAMLMKLIB) -o zip -oc camlzip $(OBJS) \
......@@ -51,7 +47,7 @@ zip.cmxa: $(OBJS:.cmo=.cmx)
zip.cmxs: zip.cmxa
$(OCAMLOPT) -shared -linkall -I ./ -o $@ $^
libcamlzip.a: $(C_OBJS)
libcamlzip$(EXT_LIB): $(C_OBJS)
$(OCAMLMKLIB) -oc camlzip $(C_OBJS) \
$(ZLIB_L_OPT) $(ZLIB_LIB)
......@@ -69,24 +65,12 @@ libcamlzip.a: $(C_OBJS)
clean:
rm -f *.cm*
rm -f *.o *.a *.so
rm -rf doc/
install-findlib: install
install:
mkdir -p $(INSTALLDIR)
cp zip.cma zip.cmi gzip.cmi zlib.cmi zip.mli gzip.mli zlib.mli libcamlzip.a $(INSTALLDIR)
if test -f dllcamlzip.so; then \
cp dllcamlzip.so $(INSTALLDIR); \
ldconf=`$(OCAMLC) -where`/ld.conf; \
installdir=$(INSTALLDIR); \
if test `grep -s -c $$installdir'$$' $$ldconf || :` = 0; \
then echo $$installdir >> $$ldconf; fi \
fi
installopt:
cp zip.cmxa $(CMXS) zip.a zip.cmx gzip.cmx zlib.cmx $(INSTALLDIR)
install-findlib:
cp META-zip META && \
ocamlfind install zip META *.mli *.a *.cmi *.cma $(wildcard *.cmx) $(wildcard *.cmxa) $(wildcard *.cmxs) $(wildcard *.so) && \
ocamlfind install zip META *.mli *.a *.cmi *.cma $(wildcard *.cmx) $(wildcard *.cmxa) $(wildcard *.cmxs) $(wildcard *$(EXT_DLL)) && \
rm META
cp META-camlzip META && \
ocamlfind install camlzip META && \
......@@ -94,6 +78,10 @@ install-findlib:
depend:
gcc -MM $(ZLIB_I_OPT) *.c > .depend
ocamldep *.mli *.ml >> .depend
$(OCAMLDEP) *.mli *.ml >> .depend
include .depend
doc: *.mli
mkdir -p doc
ocamldoc -d doc/ -html *.mli
......@@ -10,9 +10,11 @@ REQUIREMENTS:
- Objective Caml 4.02 or up.
- The Findlib / ocamlfind library manager.
- The Zlib C library, version 1.1.3 or up. If it is not installed on
your system (look for libz.a or libz.so), get it from
http://www.gzip.org/. If you are running Linux or BSD, chances
https://zlib.net/. If you are running Linux or BSD, chances
are that your distribution provides precompiled binaries for this
library.
......@@ -29,9 +31,7 @@ INSTALLATION:
- Become super-user if necessary and do
make install
make installopt # if you did "make allopt" earlier
or make install-findlib # to install using ocamlfind
This installs the library in the standard Objective Caml library directory.
This installs the library through ocamlfind.
......@@ -39,9 +39,8 @@ DOCUMENTATION:
See the comments in files zip.mli and gzip.mli.
Compilation options: -I +zip
ocamlc linking options: -I +zip zip.cma
ocamlopt linking options: -I +zip zip.cmxa
Compilation: ocamlfind ocamlopt -package zip ...
Linking: ocamlfind ocamlopt -package zip -linkpgk ...
The directory test/ contains examples of using this library.
......
......@@ -74,7 +74,11 @@ let open_in_chan ic =
in_crc = Int32.zero }
let open_in filename =
open_in_chan (Pervasives.open_in_bin filename)
let ic = Pervasives.open_in_bin filename in
try
open_in_chan ic
with exn ->
Pervasives.close_in ic; raise exn
let read_byte iz =
if iz.in_avail = 0 then begin
......
......@@ -131,8 +131,8 @@ let read_ecd filename ic =
let newlen = min (toread + len) 256 in
(* Search for magic number *)
let ofs = strrstr "PK\005\006" buf 0 newlen in
if ofs < 0 || newlen < 22 ||
(let comment_len =
if ofs < 0 || newlen < 22 ||
(let comment_len =
(Char.code (Bytes.get buf (ofs + 20)))
lor ((Char.code (Bytes.get buf (ofs + 21))) lsl 8) in
Int64.(add newpos (of_int (ofs + 22 + comment_len))) <> filelen) then
......@@ -210,7 +210,7 @@ let read_cd filename ic cd_entries cd_offset cd_bound =
} :: !e
done;
assert((cd_bound = (LargeFile.pos_in ic)) &&
(cd_entries = 65535 || !entrycnt = cd_entries));
(cd_entries = 65535 || cd_entries = !entrycnt land 0xffff));
List.rev !e
with End_of_file ->
raise (Error(filename, "", "end-of-file while reading central directory"))
......@@ -219,16 +219,19 @@ let read_cd filename ic cd_entries cd_offset cd_bound =
let open_in filename =
let ic = Pervasives.open_in_bin filename in
let (cd_entries, cd_size, cd_offset, cd_comment) = read_ecd filename ic in
let entries =
read_cd filename ic cd_entries cd_offset (Int32.add cd_offset cd_size) in
let dir = Hashtbl.create (cd_entries / 3) in
List.iter (fun e -> Hashtbl.add dir e.filename e) entries;
{ if_filename = filename;
if_channel = ic;
if_entries = entries;
if_directory = dir;
if_comment = cd_comment }
try
let (cd_entries, cd_size, cd_offset, cd_comment) = read_ecd filename ic in
let entries =
read_cd filename ic cd_entries cd_offset (Int32.add cd_offset cd_size) in
let dir = Hashtbl.create (cd_entries / 3) in
List.iter (fun e -> Hashtbl.add dir e.filename e) entries;
{ if_filename = filename;
if_channel = ic;
if_entries = entries;
if_directory = dir;
if_comment = cd_comment }
with exn ->
Pervasives.close_in ic; raise exn
(* Close a ZIP file opened for reading *)
......@@ -307,7 +310,7 @@ let read_entry ifile e =
Bytes.unsafe_to_string res
with End_of_file ->
raise (Error(ifile.if_filename, e.filename, "truncated data"))
(* Write the contents of an entry into an out channel *)
let copy_entry_to_channel ifile e oc =
......@@ -346,7 +349,7 @@ let copy_entry_to_channel ifile e oc =
raise (Error(ifile.if_filename, e.filename, "CRC mismatch"))
with End_of_file ->
raise (Error(ifile.if_filename, e.filename, "truncated data"))
(* Write the contents of an entry to a file *)
let copy_entry_to_file ifile e outfilename =
......@@ -471,7 +474,7 @@ let add_data_descriptor ofile crc compr_size uncompr_size entry =
(* Add an entry with the contents of a string *)
let add_entry data ofile ?(extra = "") ?(comment = "")
let add_entry data ofile ?(extra = "") ?(comment = "")
?(level = 6) ?(mtime = Unix.time()) name =
let e = add_entry_header ofile extra comment level mtime name in
let crc = Zlib.update_crc_string Int32.zero data 0 (String.length data) in
......@@ -502,7 +505,7 @@ let add_entry data ofile ?(extra = "") ?(comment = "")
(* Add an entry with the contents of an in channel *)
let copy_channel_to_entry ic ofile ?(extra = "") ?(comment = "")
let copy_channel_to_entry ic ofile ?(extra = "") ?(comment = "")
?(level = 6) ?(mtime = Unix.time()) name =
let e = add_entry_header ofile extra comment level mtime name in
let crc = ref Int32.zero in
......@@ -529,7 +532,7 @@ let copy_channel_to_entry ic ofile ?(extra = "") ?(comment = "")
crc := Zlib.update_crc !crc buf 0 r;
in_pos := !in_pos + r;
r)
(fun buf n ->
(fun buf n ->
output ofile.of_channel buf 0 n;
out_pos := !out_pos + n);
(!out_pos, !in_pos)
......@@ -540,11 +543,11 @@ let copy_channel_to_entry ic ofile ?(extra = "") ?(comment = "")
(* Add an entry with the contents of a file *)
let copy_file_to_entry infilename ofile ?(extra = "") ?(comment = "")
let copy_file_to_entry infilename ofile ?(extra = "") ?(comment = "")
?(level = 6) ?mtime name =
let ic = open_in_bin infilename in
let mtime' =
match mtime with
match mtime with
Some t -> mtime
| None ->
try Some((Unix.stat infilename).Unix.st_mtime)
......
......@@ -31,6 +31,10 @@ external deflate:
stream -> bytes -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_deflate_bytecode" "camlzip_deflate"
external deflate_string:
stream -> string -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_deflate_bytecode" "camlzip_deflate"
external deflate_end: stream -> unit = "camlzip_deflateEnd"
external inflate_init: bool -> stream = "camlzip_inflateInit"
......@@ -38,6 +42,10 @@ external inflate:
stream -> bytes -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_inflate_bytecode" "camlzip_inflate"
external inflate_string:
stream -> string -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_inflate_bytecode" "camlzip_inflate"
external inflate_end: stream -> unit = "camlzip_inflateEnd"
external update_crc: int32 -> bytes -> int -> int -> int32
......@@ -87,6 +95,7 @@ let compress_direct ?(level = 6) ?(header = true) flush =
outbuf 0 buffer_size Z_FINISH in
flush outbuf used_out;
if not finished then compr_finish()
else deflate_end zs
in
compr, compr_finish
......
......@@ -39,6 +39,10 @@ external deflate:
stream -> bytes -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_deflate_bytecode" "camlzip_deflate"
external deflate_string:
stream -> string -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_deflate_bytecode" "camlzip_deflate"
external deflate_end: stream -> unit = "camlzip_deflateEnd"
external inflate_init: bool -> stream = "camlzip_inflateInit"
......@@ -46,6 +50,10 @@ external inflate:
stream -> bytes -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_inflate_bytecode" "camlzip_inflate"
external inflate_string:
stream -> string -> int -> int -> bytes -> int -> int -> flush_command
-> bool * int * int
= "camlzip_inflate_bytecode" "camlzip_inflate"
external inflate_end: stream -> unit = "camlzip_inflateEnd"
external update_crc: int32 -> bytes -> int -> int -> int32
......
......@@ -105,7 +105,7 @@ value camlzip_deflate(value vzs, value srcbuf, value srcpos, value srclen,
zs->next_out = &Byte_u(dstbuf, Long_val(dstpos));
zs->avail_out = Long_val(dstlen);
retcode = deflate(zs, camlzip_flush_table[Int_val(vflush)]);
if (retcode < 0) camlzip_error("Zlib.deflate", vzs);
if (retcode < 0 && retcode != Z_BUF_ERROR) camlzip_error("Zlib.deflate", vzs);
used_in = Long_val(srclen) - zs->avail_in;
used_out = Long_val(dstlen) - zs->avail_out;
zs->next_in = NULL; /* not required, but cleaner */
......@@ -153,7 +153,7 @@ value camlzip_inflate(value vzs, value srcbuf, value srcpos, value srclen,
zs->next_out = &Byte_u(dstbuf, Long_val(dstpos));
zs->avail_out = Long_val(dstlen);
retcode = inflate(zs, camlzip_flush_table[Int_val(vflush)]);
if (retcode < 0 || retcode == Z_NEED_DICT)
if ((retcode < 0 && retcode != Z_BUF_ERROR) || retcode == Z_NEED_DICT)
camlzip_error("Zlib.inflate", vzs);
used_in = Long_val(srclen) - zs->avail_in;
used_out = Long_val(dstlen) - zs->avail_out;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment