This is an automated email from the git hooks/post-receive script. treinen pushed a commit to branch master in repository camlzip.
commit ff813e389c39bd4b3f86ce222add09277a0a81d0 Author: Ralf Treinen <trei...@free.fr> Date: Thu Sep 8 20:40:58 2016 +0200 New upstream version 1.06 --- Changes | 7 +++++ META | 2 +- Makefile | 12 ++++---- README | 4 +-- gzip.ml | 62 +++++++++++++++++++++++------------------ gzip.mli | 12 +++++--- test/minigzip.ml | 8 +++--- test/minizip.ml | 2 +- zip.ml | 84 +++++++++++++++++++++++++++++--------------------------- zip.mli | 6 ++-- zlib.ml | 23 +++++++++------- zlib.mli | 18 ++++++------ zlibstubs.c | 5 ++-- 13 files changed, 137 insertions(+), 108 deletions(-) diff --git a/Changes b/Changes index 0ff2ad4..3e24fff 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,10 @@ +Release 1.06: +- Switch to "safe string" mode. Some API functions that use to take strings + now take byte sequences instead. OCaml 4.02 or up is required. +- Update for OCaml 4.03. +- Avoid Zlib error when calling Gzip.output with length = 0. +- Improve support for ZIP files / ZIP file members greater than 2 Gbytes. + Release 1.05: - Added support for findlib (Contributed by E. Friendly) diff --git a/META b/META index 9ea2d10..cc4c1b3 100644 --- a/META +++ b/META @@ -1,4 +1,4 @@ -version="1.05" +version="1.06" requires="unix" archive(byte)="zip.cma" archive(native)="zip.cmxa" diff --git a/Makefile b/Makefile index a9f7178..1e1503f 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,12 @@ ZLIB_LIB=-lz # The directory containing the Zlib library (libz.a or libz.so) -ZLIB_LIBDIR=/usr/local/lib +ZLIB_LIBDIR=/usr/lib +# ZLIB_LIBDIR=/usr/local/lib # The directory containing the Zlib header file (zlib.h) -ZLIB_INCLUDE=/usr/local/include +ZLIB_INCLUDE=/usr/include +# ZLIB_INCLUDE=/usr/local/include # Where to install the library. By default: sub-directory 'zip' of # OCaml's standard library directory. @@ -15,8 +17,8 @@ INSTALLDIR=`$(OCAMLC) -where`/zip ### End of configuration section -OCAMLC=ocamlc -g -OCAMLOPT=ocamlopt +OCAMLC=ocamlc -g -safe-string +OCAMLOPT=ocamlopt -safe-string OCAMLDEP=ocamldep OCAMLMKLIB=ocamlmklib @@ -52,7 +54,7 @@ libcamlzip.a: $(C_OBJS) clean: rm -f *.cm* - rm -f *.o *.a + rm -f *.o *.a *.so install: mkdir -p $(INSTALLDIR) diff --git a/README b/README index 68dc7da..847be91 100644 --- a/README +++ b/README @@ -8,7 +8,7 @@ for reading from and writing to compressed files in these formats. REQUIREMENTS: -- Objective Caml 3.06 or up. +- Objective Caml 4.02 or up. - 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 @@ -47,7 +47,7 @@ The directory test/ contains examples of using this library. LICENSING: -This library is copyright 2001, 2002, 2006, 2007, 2008 +This library is copyright 2001, 2002, 2006, 2007, 2008, 2016 Institut National de Recherche en Informatique et en Automatique (INRIA), and distributed under the terms of the GNU Lesser General Public License (LGPL) version 2.1 or above, with a special exception diff --git a/gzip.ml b/gzip.ml index b823b8c..b90d46b 100644 --- a/gzip.ml +++ b/gzip.ml @@ -11,7 +11,7 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: gzip.ml 32 2016-06-10 09:30:19Z xleroy $ *) (* Module [Gzip]: reading and writing to/from [gzip] compressed files *) @@ -21,7 +21,7 @@ let buffer_size = 1024 type in_channel = { in_chan: Pervasives.in_channel; - in_buffer: string; + in_buffer: bytes; mutable in_pos: int; mutable in_avail: int; mutable in_eof: bool; @@ -65,7 +65,7 @@ let open_in_chan ic = raise(Error("premature end of file, not a gzip file")) end; { in_chan = ic; - in_buffer = String.create buffer_size; + in_buffer = Bytes.create buffer_size; in_pos = 0; in_avail = 0; in_eof = false; @@ -79,12 +79,12 @@ let open_in filename = let read_byte iz = if iz.in_avail = 0 then begin let n = Pervasives.input iz.in_chan iz.in_buffer 0 - (String.length iz.in_buffer) in + (Bytes.length iz.in_buffer) in if n = 0 then raise End_of_file; iz.in_pos <- 0; iz.in_avail <- n end; - let c = iz.in_buffer.[iz.in_pos] in + let c = Bytes.get iz.in_buffer iz.in_pos in iz.in_pos <- iz.in_pos + 1; iz.in_avail <- iz.in_avail - 1; Char.code c @@ -100,12 +100,12 @@ let read_int32 iz = (Int32.shift_left (Int32.of_int b4) 24))) let rec input iz buf pos len = - if pos < 0 || len < 0 || pos + len > String.length buf then + if pos < 0 || len < 0 || pos + len > Bytes.length buf then invalid_arg "Gzip.input"; if iz.in_eof then 0 else begin if iz.in_avail = 0 then begin let n = Pervasives.input iz.in_chan iz.in_buffer 0 - (String.length iz.in_buffer) in + (Bytes.length iz.in_buffer) in if n = 0 then raise(Error("truncated file")); iz.in_pos <- 0; iz.in_avail <- n @@ -146,10 +146,12 @@ let rec really_input iz buf pos len = really_input iz buf (pos + n) (len - n) end -let char_buffer = String.create 1 +let char_buffer = Bytes.create 1 let input_char iz = - if input iz char_buffer 0 1 = 0 then raise End_of_file else char_buffer.[0] + if input iz char_buffer 0 1 = 0 + then raise End_of_file + else Bytes.get char_buffer 0 let input_byte iz = Char.code (input_char iz) @@ -164,7 +166,7 @@ let close_in iz = type out_channel = { out_chan: Pervasives.out_channel; - out_buffer: string; + out_buffer: bytes; mutable out_pos: int; mutable out_avail: int; out_stream: Zlib.stream; @@ -182,7 +184,7 @@ let open_out_chan ?(level = 6) oc = output_byte oc 0; (* xflags *) output_byte oc 0xFF; (* OS (unknown) *) { out_chan = oc; - out_buffer = String.create buffer_size; + out_buffer = Bytes.create buffer_size; out_pos = 0; out_avail = buffer_size; out_stream = Zlib.deflate_init level false; @@ -193,29 +195,35 @@ let open_out ?(level = 6) filename = open_out_chan ~level (Pervasives.open_out_bin filename) let rec output oz buf pos len = - if pos < 0 || len < 0 || pos + len > String.length buf then + if pos < 0 || len < 0 || pos + len > Bytes.length buf then invalid_arg "Gzip.output"; (* If output buffer is full, flush it *) if oz.out_avail = 0 then begin Pervasives.output oz.out_chan oz.out_buffer 0 oz.out_pos; oz.out_pos <- 0; - oz.out_avail <- String.length oz.out_buffer + oz.out_avail <- Bytes.length oz.out_buffer end; - let (_, used_in, used_out) = - try - Zlib.deflate oz.out_stream buf pos len - oz.out_buffer oz.out_pos oz.out_avail - Zlib.Z_NO_FLUSH - with Zlib.Error(_, _) -> - raise (Error("error during compression")) in - oz.out_pos <- oz.out_pos + used_out; - oz.out_avail <- oz.out_avail - used_out; - oz.out_size <- Int32.add oz.out_size (Int32.of_int used_in); - oz.out_crc <- Zlib.update_crc oz.out_crc buf pos used_in; - if used_in < len then output oz buf (pos + used_in) (len - used_in) + (* Patch request #1428: Zlib disallows zero-length writes *) + if len > 0 then begin + let (_, used_in, used_out) = + try + Zlib.deflate oz.out_stream buf pos len + oz.out_buffer oz.out_pos oz.out_avail + Zlib.Z_NO_FLUSH + with Zlib.Error(_, _) -> + raise (Error("error during compression")) in + oz.out_pos <- oz.out_pos + used_out; + oz.out_avail <- oz.out_avail - used_out; + oz.out_size <- Int32.add oz.out_size (Int32.of_int used_in); + oz.out_crc <- Zlib.update_crc oz.out_crc buf pos used_in; + if used_in < len then output oz buf (pos + used_in) (len - used_in) + end + +let output_substring oz buf pos len = + output oz (Bytes.unsafe_of_string buf) pos len let output_char oz c = - char_buffer.[0] <- c; + Bytes.set char_buffer 0 c; output oz char_buffer 0 1 let output_byte oz b = @@ -234,7 +242,7 @@ let flush oz = if oz.out_avail = 0 then begin Pervasives.output oz.out_chan oz.out_buffer 0 oz.out_pos; oz.out_pos <- 0; - oz.out_avail <- String.length oz.out_buffer + oz.out_avail <- Bytes.length oz.out_buffer end; let (finished, _, used_out) = Zlib.deflate oz.out_stream oz.out_buffer 0 0 diff --git a/gzip.mli b/gzip.mli index 0f3633f..316b479 100644 --- a/gzip.mli +++ b/gzip.mli @@ -11,7 +11,7 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: gzip.mli 32 2016-06-10 09:30:19Z xleroy $ *) (** Reading and writing to/from [gzip] compressed files @@ -36,7 +36,7 @@ val input_byte: in_channel -> int (** Same as [Gzip.input_char], but return the 8-bit integer representing the character. Raise [End_of_file] if no more compressed data is available. *) -val input: in_channel -> string -> int -> int -> int +val input: in_channel -> bytes -> int -> int -> int (** [input ic buf pos len] uncompresses up to [len] characters from the given channel [ic], storing them in string [buf], starting at character number [pos]. @@ -52,7 +52,7 @@ val input: in_channel -> string -> int -> int -> int exactly [len] characters.) Exception [Invalid_argument "Gzip.input"] is raised if [pos] and [len] do not designate a valid substring of [buf]. *) -val really_input: in_channel -> string -> int -> int -> unit +val really_input: in_channel -> bytes -> int -> int -> unit (** [really_input ic buf pos len] uncompresses [len] characters from the given channel, storing them in string [buf], starting at character number [pos]. @@ -96,12 +96,16 @@ val output_char: out_channel -> char -> unit val output_byte: out_channel -> int -> unit (** Same as [Gzip.output_char], but the output character is given by its code. The given integer is taken modulo 256. *) -val output: out_channel -> string -> int -> int -> unit +val output: out_channel -> bytes -> int -> int -> unit (** [output oc buf pos len] compresses and writes [len] characters from string [buf], starting at offset [pos], and writes the compressed data to the channel [oc]. Raise [Invalid_argument "Gzip.output"] if [pos] and [len] do not designate a valid substring of [buf]. *) +val output_substring: out_channel -> string -> int -> int -> unit + (** Same as [output], but takes a string as argument instead of + a byte sequence. + @since 1.06 *) val close_out: out_channel -> unit (** Close the given output channel. If the channel was created with [Gzip.open_out_chan], the underlying regular file channel diff --git a/test/minigzip.ml b/test/minigzip.ml index f3d2f4c..79e1837 100644 --- a/test/minigzip.ml +++ b/test/minigzip.ml @@ -11,23 +11,23 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: minigzip.ml 32 2016-06-10 09:30:19Z xleroy $ *) -let buffer = String.create 4096 +let buffer = Bytes.create 4096 let _ = if Array.length Sys.argv >= 2 && Sys.argv.(1) = "-d" then begin (* decompress *) let ic = Gzip.open_in_chan stdin in let rec decompress () = - let n = Gzip.input ic buffer 0 (String.length buffer) in + let n = Gzip.input ic buffer 0 (Bytes.length buffer) in if n = 0 then () else begin output stdout buffer 0 n; decompress() end in decompress(); Gzip.dispose ic end else begin (* compress *) let oc = Gzip.open_out_chan stdout in let rec compress () = - let n = input stdin buffer 0 (String.length buffer) in + let n = input stdin buffer 0 (Bytes.length buffer) in if n = 0 then () else begin Gzip.output oc buffer 0 n; compress() end in compress(); Gzip.flush oc end diff --git a/test/minizip.ml b/test/minizip.ml index dcfbab4..90742d5 100644 --- a/test/minizip.ml +++ b/test/minizip.ml @@ -11,7 +11,7 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: minizip.ml 14 2006-04-04 08:29:07Z xleroy $ *) open Printf diff --git a/zip.ml b/zip.ml index f49b91a..e36b1bb 100644 --- a/zip.ml +++ b/zip.ml @@ -11,7 +11,7 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: zip.ml 35 2016-06-10 12:48:10Z xleroy $ *) (* Module [Zip]: reading and writing ZIP archives *) @@ -28,8 +28,8 @@ let read4_int ic = if hw > max_int lsr 16 then raise (Error("", "", "32-bit data too large")); lw lor (hw lsl 16) let readstring ic n = - let s = String.create n in - really_input ic s 0 n; s + let s = Bytes.create n in + really_input ic s 0 n; Bytes.unsafe_to_string s let write1 = output_byte let write2 oc n = @@ -41,7 +41,7 @@ let write4_int oc n = write2 oc n; write2 oc (n lsr 16) let writestring oc s = - output oc s 0 (String.length s) + output_string oc s type compression_method = Stored | Deflated @@ -73,16 +73,14 @@ type out_file = mutable of_entries: entry list; of_comment: string } -exception Error of string * string * string - -(* Return the position of the last occurrence of s1 in s2, or -1 if not - found. *) +(* Return the position of the last occurrence of [pattern] in [buf], + or -1 if not found. *) -let strrstr pattern buf ofs len = +let strrstr (pattern: string) (buf: bytes) ofs len = let rec search i j = if i < ofs then -1 else if j >= String.length pattern then i - else if pattern.[j] = buf.[i + j] then search i (j+1) + else if String.get pattern j = Bytes.get buf (i + j) then search i (j+1) else search (i-1) 0 in search (ofs + len - String.length pattern) 0 @@ -117,30 +115,31 @@ let dostime_of_unixtime t = (* Read end of central directory record *) let read_ecd filename ic = - let buf = String.create 256 in - let filelen = in_channel_length ic in + let buf = Bytes.create 256 in + let filelen = LargeFile.in_channel_length ic in let rec find_ecd pos len = (* On input, bytes 0 ... len - 1 of buf reflect what is at pos in ic *) - if pos <= 0 || filelen - pos >= 0x10000 then + if pos <= 0L || Int64.sub filelen pos >= 0x10000L then raise (Error(filename, "", "end of central directory not found, not a ZIP file")); - let toread = min pos 128 in + let toread = if pos >= 128L then 128 else Int64.to_int pos in (* Make room for "toread" extra bytes, and read them *) - String.blit buf 0 buf toread (256 - toread); - let newpos = pos - toread in - seek_in ic newpos; + Bytes.blit buf 0 buf toread (256 - toread); + let newpos = Int64.(sub pos (of_int toread)) in + LargeFile.seek_in ic newpos; really_input ic buf 0 toread; 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 = - Char.code buf.[ofs + 20] lor (Char.code buf.[ofs + 21] lsl 8) in - newpos + ofs + 22 + comment_len <> filelen) then + (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 find_ecd newpos newlen else - newpos + ofs in - seek_in ic (find_ecd filelen 0); + Int64.(add newpos (of_int ofs)) in + LargeFile.seek_in ic (find_ecd filelen 0); let magic = read4 ic in let disk_no = read2 ic in let cd_disk_no = read2 ic in @@ -157,10 +156,13 @@ let read_ecd filename ic = (* Read central directory *) +let int64_of_uint32 n = + Int64.(logand (of_int32 n) 0xFFFF_FFFFL) + let read_cd filename ic cd_entries cd_offset cd_bound = - let cd_bound = Int64.of_int32 cd_bound in + let cd_bound = int64_of_uint32 cd_bound in try - LargeFile.seek_in ic (Int64.of_int32 cd_offset); + LargeFile.seek_in ic (int64_of_uint32 cd_offset); let e = ref [] in let entrycnt = ref 0 in while (LargeFile.pos_in ic < cd_bound) do @@ -181,7 +183,7 @@ let read_cd filename ic cd_entries cd_offset cd_bound = let _disk_number = read2 ic in let _internal_attr = read2 ic in let _external_attr = read4 ic in - let header_offset = Int64.of_int32(read4 ic) in + let header_offset = int64_of_uint32 (read4 ic) in let name = readstring ic name_len in let extra = readstring ic extra_len in let comment = readstring ic comment_len in @@ -269,14 +271,14 @@ let goto_entry ifile e = let read_entry ifile e = try goto_entry ifile e; - let res = String.create e.uncompressed_size in + let res = Bytes.create e.uncompressed_size in match e.methd with Stored -> if e.compressed_size <> e.uncompressed_size then raise (Error(ifile.if_filename, e.filename, "wrong size for stored entry")); really_input ifile.if_channel res 0 e.uncompressed_size; - res + Bytes.unsafe_to_string res | Deflated -> let in_avail = ref e.compressed_size in let out_pos = ref 0 in @@ -284,25 +286,25 @@ let read_entry ifile e = Zlib.uncompress ~header:false (fun buf -> let read = input ifile.if_channel buf 0 - (min !in_avail (String.length buf)) in + (min !in_avail (Bytes.length buf)) in in_avail := !in_avail - read; read) (fun buf len -> - if !out_pos + len > String.length res then + if !out_pos + len > Bytes.length res then raise (Error(ifile.if_filename, e.filename, "wrong size for deflated entry (too much data)")); - String.blit buf 0 res !out_pos len; + Bytes.blit buf 0 res !out_pos len; out_pos := !out_pos + len) with Zlib.Error(_, _) -> raise (Error(ifile.if_filename, e.filename, "decompression error")) end; - if !out_pos <> String.length res then + if !out_pos <> Bytes.length res then raise (Error(ifile.if_filename, e.filename, "wrong size for deflated entry (not enough data)")); - let crc = Zlib.update_crc Int32.zero res 0 (String.length res) in + let crc = Zlib.update_crc Int32.zero res 0 (Bytes.length res) in if crc <> e.crc then raise (Error(ifile.if_filename, e.filename, "CRC mismatch")); - res + Bytes.unsafe_to_string res with End_of_file -> raise (Error(ifile.if_filename, e.filename, "truncated data")) @@ -316,10 +318,10 @@ let copy_entry_to_channel ifile e oc = if e.compressed_size <> e.uncompressed_size then raise (Error(ifile.if_filename, e.filename, "wrong size for stored entry")); - let buf = String.create 4096 in + let buf = Bytes.create 4096 in let rec copy n = if n > 0 then begin - let r = input ifile.if_channel buf 0 (min n (String.length buf)) in + let r = input ifile.if_channel buf 0 (min n (Bytes.length buf)) in output oc buf 0 r; copy (n - r) end in @@ -331,7 +333,7 @@ let copy_entry_to_channel ifile e oc = Zlib.uncompress ~header:false (fun buf -> let read = input ifile.if_channel buf 0 - (min !in_avail (String.length buf)) in + (min !in_avail (Bytes.length buf)) in in_avail := !in_avail - read; read) (fun buf len -> @@ -472,11 +474,11 @@ let add_data_descriptor ofile crc compr_size uncompr_size entry = 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 Int32.zero data 0 (String.length data) in + let crc = Zlib.update_crc_string Int32.zero data 0 (String.length data) in let compr_size = match level with 0 -> - output ofile.of_channel data 0 (String.length data); + output_substring ofile.of_channel data 0 (String.length data); String.length data | _ -> let in_pos = ref 0 in @@ -485,7 +487,7 @@ let add_entry data ofile ?(extra = "") ?(comment = "") Zlib.compress ~level ~header:false (fun buf -> let n = min (String.length data - !in_pos) - (String.length buf) in + (Bytes.length buf) in String.blit data !in_pos buf 0 n; in_pos := !in_pos + n; n) @@ -507,9 +509,9 @@ let copy_channel_to_entry ic ofile ?(extra = "") ?(comment = "") let (compr_size, uncompr_size) = match level with 0 -> - let buf = String.create 4096 in + let buf = Bytes.create 4096 in let rec copy sz = - let r = input ic buf 0 (String.length buf) in + let r = input ic buf 0 (Bytes.length buf) in if r = 0 then sz else begin crc := Zlib.update_crc !crc buf 0 r; output ofile.of_channel buf 0 r; @@ -523,7 +525,7 @@ let copy_channel_to_entry ic ofile ?(extra = "") ?(comment = "") try Zlib.compress ~level ~header:false (fun buf -> - let r = input ic buf 0 (String.length buf) in + let r = input ic buf 0 (Bytes.length buf) in crc := Zlib.update_crc !crc buf 0 r; in_pos := !in_pos + r; r) diff --git a/zip.mli b/zip.mli index 8f7e3ad..7fc25ce 100644 --- a/zip.mli +++ b/zip.mli @@ -11,7 +11,7 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: zip.mli 32 2016-06-10 09:30:19Z xleroy $ *) (** Reading and writing ZIP archives @@ -146,7 +146,7 @@ val copy_file_to_entry: val add_entry_generator: out_file -> ?extra: string -> ?comment: string -> ?level: int -> - ?mtime: float -> string -> (string -> int -> int -> unit) * (unit -> unit) + ?mtime: float -> string -> (bytes -> int -> int -> unit) * (unit -> unit) (** [Zip.add_entry_generator zf name] returns a pair of functions [(add, finish)]. It adds a new entry to the ZIP file [zf]. The file name stored along with this entry @@ -154,7 +154,7 @@ val add_entry_generator: To store data in this entry, the program must repeatedly call the [add] function returned by [Zip.add_entry_generator]. An invocation [add s ofs len] stores [len] characters of - string [s] starting at offset [ofs] in the ZIP entry. + byte sequence [s] starting at offset [ofs] in the ZIP entry. When all the data forming the entry has been sent, the program must call the [finish] function returned by [Zip.add_entry_generator]. [finish] must be called exactly once. diff --git a/zlib.ml b/zlib.ml index d55a3e4..186ac26 100644 --- a/zlib.ml +++ b/zlib.ml @@ -11,7 +11,7 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: zlib.ml 32 2016-06-10 09:30:19Z xleroy $ *) exception Error of string * string @@ -28,26 +28,28 @@ type flush_command = external deflate_init: int -> bool -> stream = "camlzip_deflateInit" external deflate: - stream -> string -> int -> int -> string -> int -> int -> flush_command + stream -> bytes -> 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" external inflate: - stream -> string -> int -> int -> string -> int -> int -> flush_command + stream -> bytes -> 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 -> string -> int -> int -> int32 +external update_crc: int32 -> bytes -> int -> int -> int32 + = "camlzip_update_crc32" +external update_crc_string: int32 -> string -> int -> int -> int32 = "camlzip_update_crc32" let buffer_size = 1024 let compress ?(level = 6) ?(header = true) refill flush = - let inbuf = String.create buffer_size - and outbuf = String.create buffer_size in + let inbuf = Bytes.create buffer_size + and outbuf = Bytes.create buffer_size in let zs = deflate_init level header in let rec compr inpos inavail = if inavail = 0 then begin @@ -69,7 +71,7 @@ let compress ?(level = 6) ?(header = true) refill flush = deflate_end zs let compress_direct ?(level = 6) ?(header = true) flush = - let outbuf = String.create buffer_size in + let outbuf = Bytes.create buffer_size in let zs = deflate_init level header in let rec compr inbuf inpos inavail = if inavail = 0 then () @@ -81,15 +83,16 @@ let compress_direct ?(level = 6) ?(header = true) flush = end and compr_finish () = let (finished, _, used_out) = - deflate zs "" 0 0 outbuf 0 buffer_size Z_FINISH in + deflate zs (Bytes.unsafe_of_string "") 0 0 + outbuf 0 buffer_size Z_FINISH in flush outbuf used_out; if not finished then compr_finish() in compr, compr_finish let uncompress ?(header = true) refill flush = - let inbuf = String.create buffer_size - and outbuf = String.create buffer_size in + let inbuf = Bytes.create buffer_size + and outbuf = Bytes.create buffer_size in let zs = inflate_init header in let rec uncompr inpos inavail = if inavail = 0 then begin diff --git a/zlib.mli b/zlib.mli index f4c8dd1..e1c75c6 100644 --- a/zlib.mli +++ b/zlib.mli @@ -11,20 +11,20 @@ (* *) (***********************************************************************) -(* $Id$ *) +(* $Id: zlib.mli 32 2016-06-10 09:30:19Z xleroy $ *) exception Error of string * string val compress: ?level: int -> ?header: bool -> - (string -> int) -> (string -> int -> unit) -> unit + (bytes -> int) -> (bytes -> int -> unit) -> unit val compress_direct: - ?level: int -> ?header: bool -> (string -> int -> unit) -> - (string -> int -> int -> unit) * (unit -> unit) + ?level: int -> ?header: bool -> (bytes -> int -> unit) -> + (bytes -> int -> int -> unit) * (unit -> unit) val uncompress: - ?header: bool -> (string -> int) -> (string -> int -> unit) -> unit + ?header: bool -> (bytes -> int) -> (bytes -> int -> unit) -> unit type stream @@ -36,17 +36,19 @@ type flush_command = external deflate_init: int -> bool -> stream = "camlzip_deflateInit" external deflate: - stream -> string -> int -> int -> string -> int -> int -> flush_command + stream -> bytes -> 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" external inflate: - stream -> string -> int -> int -> string -> int -> int -> flush_command + stream -> bytes -> 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 -> string -> int -> int -> int32 +external update_crc: int32 -> bytes -> int -> int -> int32 + = "camlzip_update_crc32" +external update_crc_string: int32 -> string -> int -> int -> int32 = "camlzip_update_crc32" diff --git a/zlibstubs.c b/zlibstubs.c index a627df9..661729a 100644 --- a/zlibstubs.c +++ b/zlibstubs.c @@ -11,10 +11,11 @@ /* */ /***********************************************************************/ -/* $Id$ */ +/* $Id: zlibstubs.c 33 2016-06-10 12:37:25Z xleroy $ */ /* Stub code to interface with Zlib */ +#include <stdint.h> #include <zlib.h> #include <caml/mlvalues.h> @@ -168,7 +169,7 @@ value camlzip_inflateEnd(value vzs) value camlzip_update_crc32(value crc, value buf, value pos, value len) { - return caml_copy_int32(crc32((uint32) Int32_val(crc), + return caml_copy_int32(crc32((uint32_t) Int32_val(crc), &Byte_u(buf, Long_val(pos)), Long_val(len))); } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/camlzip.git _______________________________________________ Pkg-ocaml-maint-commits mailing list Pkg-ocaml-maint-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-ocaml-maint-commits