File: testzlib.ml

package info (click to toggle)
camlzip 1.01-15
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 168 kB
  • ctags: 250
  • sloc: ml: 924; ansic: 139; makefile: 116; sh: 98
file content (21 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (8)
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 (String.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 (String.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)