File: minigzip.ml

package info (click to toggle)
camlzip 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: ml: 1,244; ansic: 171; sh: 121; makefile: 101
file content (33 lines) | stat: -rw-r--r-- 1,575 bytes parent folder | download | duplicates (3)
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
(***********************************************************************)
(*                                                                     *)
(*                         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$ *)

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 (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 (Bytes.length buffer) in
      if n = 0 then () else begin Gzip.output oc buffer 0 n; Gzip.flush_continue oc; compress() end
    in compress(); Gzip.flush oc
  end