File: testzlib.ml

package info (click to toggle)
camlzip 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: ml: 1,283; ansic: 171; sh: 121; makefile: 101
file content (21 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let compress infile outfile =
  let ic = open_in_bin infile
  and oc = open_out_bin outfile in
  Zlib.compress (fun buf -> input ic buf 0 (Bytes.length buf))
                (fun buf len -> output oc buf 0 len);
  close_in ic;
  close_out oc

let uncompress infile outfile =
  let ic = open_in_bin infile
  and oc = open_out_bin outfile in
  Zlib.uncompress (fun buf -> input ic buf 0 (Bytes.length buf))
                  (fun buf len -> output oc buf 0 len);
  close_in ic;
  close_out oc

let _ =
  if Array.length Sys.argv >= 4 && Sys.argv.(1) = "-d" then
    uncompress Sys.argv.(2) Sys.argv.(3)
  else if Array.length Sys.argv >= 3 then
    compress Sys.argv.(1) Sys.argv.(2)