/usr/share/doc/libzip-ocaml-dev/examples/minizip.ml is in libzip-ocaml-dev 1.06-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | (***********************************************************************)
(* *)
(* The CamlZip library *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 2001 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed *)
(* under the terms of the GNU Library General Public License, with *)
(* the special exception on linking described in file LICENSE. *)
(* *)
(***********************************************************************)
(* $Id: minizip.ml 14 2006-04-04 08:29:07Z xleroy $ *)
open Printf
let list_entry e =
let t = Unix.localtime e.Zip.mtime in
printf "%6d %6d %c %04d-%02d-%02d %02d:%02d %c %s\n"
e.Zip.uncompressed_size
e.Zip.compressed_size
(match e.Zip.methd with Zip.Stored -> 's' | Zip.Deflated -> 'd')
(t.Unix.tm_year + 1900) (t.Unix.tm_mon + 1) t.Unix.tm_mday
t.Unix.tm_hour t.Unix.tm_min
(if e.Zip.is_directory then 'd' else ' ')
e.Zip.filename;
if e.Zip.comment <> "" then
printf " %s\n" e.Zip.comment
let list zipfile =
let ic = Zip.open_in zipfile in
if Zip.comment ic <> "" then printf "%s\n" (Zip.comment ic);
List.iter list_entry (Zip.entries ic);
Zip.close_in ic
let extract_entry ifile e =
print_string e.Zip.filename; print_newline();
if e.Zip.is_directory then begin
try
Unix.mkdir e.Zip.filename 0o777
with Unix.Unix_error(Unix.EEXIST, _, _) -> ()
end else begin
Zip.copy_entry_to_file ifile e e.Zip.filename
end
let extract zipfile =
let ic = Zip.open_in zipfile in
List.iter (extract_entry ic) (Zip.entries ic);
Zip.close_in ic
let rec add_entry oc file =
let s = Unix.stat file in
match s.Unix.st_kind with
Unix.S_REG ->
printf "Adding file %s\n" file; flush stdout;
Zip.copy_file_to_entry file oc ~mtime:s.Unix.st_mtime file
| Unix.S_DIR ->
printf "Adding directory %s\n" file; flush stdout;
Zip.add_entry "" oc ~mtime:s.Unix.st_mtime
(if Filename.check_suffix file "/" then file else file ^ "/");
let d = Unix.opendir file in
begin try
while true do
let e = Unix.readdir d in
if e <> "." && e <> ".." then add_entry oc (Filename.concat file e)
done
with End_of_file -> ()
end;
Unix.closedir d
| _ -> ()
let create zipfile files =
let oc = Zip.open_out zipfile in
Array.iter (add_entry oc) files;
Zip.close_out oc
let usage() =
prerr_string
"Usage:
minizip t <zipfile> show contents of <zipfile>
minizip x <zipfile> extract files from <zipfile>
minizip c <zipfile> <file> .. create a <zipfile> with the given files";
exit 2
let _ =
if Array.length Sys.argv < 3 then usage();
match Sys.argv.(1) with
"t" -> list Sys.argv.(2)
| "x" -> extract Sys.argv.(2)
| "c" -> create Sys.argv.(2)
(Array.sub Sys.argv 3 (Array.length Sys.argv - 3))
| _ -> usage()
|