From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 9B9C07F6CC for ; Mon, 2 Feb 2015 18:53:51 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of dhekuir@gmail.com) identity=pra; client-ip=209.85.213.51; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="dhekuir@gmail.com"; x-sender="dhekuir@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of dhekuir@gmail.com designates 209.85.213.51 as permitted sender) identity=mailfrom; client-ip=209.85.213.51; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="dhekuir@gmail.com"; x-sender="dhekuir@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-yh0-f51.google.com) identity=helo; client-ip=209.85.213.51; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="dhekuir@gmail.com"; x-sender="postmaster@mail-yh0-f51.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B7AQBTuc9UmzPVVdFbhDEEgn3BXQGFegKBFQdDAQEBAQERAQEBAQEGCwsJFC6EDAEBAQMBAQIPER0BGx0BAwELBgUEBwMKKgICIgERAQUBHAYTGgiHdgEDCQi0ND4xiy6Ba4J3im0KGScNVIR8AQEBAQEFAQEBAQEBFgEFDo9qB4JogUEFmC6BF4VHijQSI4EMCYIkHIFRPTGCQgEBAQ X-IPAS-Result: A0B7AQBTuc9UmzPVVdFbhDEEgn3BXQGFegKBFQdDAQEBAQERAQEBAQEGCwsJFC6EDAEBAQMBAQIPER0BGx0BAwELBgUEBwMKKgICIgERAQUBHAYTGgiHdgEDCQi0ND4xiy6Ba4J3im0KGScNVIR8AQEBAQEFAQEBAQEBFgEFDo9qB4JogUEFmC6BF4VHijQSI4EMCYIkHIFRPTGCQgEBAQ X-IronPort-AV: E=Sophos;i="5.09,507,1418079600"; d="scan'208";a="98575966" Received: from mail-yh0-f51.google.com ([209.85.213.51]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Feb 2015 18:53:49 +0100 Received: by mail-yh0-f51.google.com with SMTP id z6so16529637yhz.10 for ; Mon, 02 Feb 2015 09:53:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MVAueSJWH4egiaABSzI5tFx2r/6ShXF2pU3tvD99bn0=; b=bQHNyjEDpY4cU5xkdQQGkRTGqlMhOxr7pZXXq8vk4wA9SogC6v6UalOSVTXXP2HPIk qo8jXdp8BZ5wbrzWKmTvBL8xysCsLmaluz9Hlvo4JQIkwhne4fDdkZYvPVqRxrAd+nU7 HAqpxDpSZq5Qb+4gCDbz9rMBV1L7XAHziG/OalE8eYkR4fK9VJjTdVgSm62njEulTKjM mNzgZZVB/bFhhOG6If30MiiS3l5OtGjTFRW45xza2bfivKv4IGHS1gHiSyBBQ6OPFdq4 sTi4LQyPuExk5vgiTRojyb4ug0+3A693Ab+bUU26I4mXMWmwoVTNmnodxfQiX9nc1IPJ Ngbw== MIME-Version: 1.0 X-Received: by 10.170.115.209 with SMTP id h200mr9549344ykb.87.1422899628986; Mon, 02 Feb 2015 09:53:48 -0800 (PST) Received: by 10.170.217.194 with HTTP; Mon, 2 Feb 2015 09:53:48 -0800 (PST) In-Reply-To: References: <54CF9B20.5040300@inria.fr> <54CFAA41.20706@zoho.com> Date: Mon, 2 Feb 2015 18:53:48 +0100 Message-ID: From: Dhek Uir To: David Allsopp Cc: "caml-list@inria.fr" , Drup Content-Type: multipart/alternative; boundary=001a1137bdb4efd598050e1ea2fc Subject: Re: [Caml-list] Simple compression library --001a1137bdb4efd598050e1ea2fc Content-Type: text/plain; charset=UTF-8 Wow, I completely overlooked that. I was convinced that Gzip.input/Gzip.really_input returned the number of *compressed* characters read. I misread "uncompresses up to len characters" as "advances the compressed buffer up to len characters". The phrase "[Gzip.input] returns the actual number of characters read" didn't help me either. Anyway, thanks a lot, it's much simpler than I expected! On Mon, Feb 2, 2015 at 6:38 PM, David Allsopp wrote: > Dhek Uir wrote: > > But since camlzip does not have an input_value function, it seems I must > set up > > a buffer to decompress the data, then use Marshal to obtain input data > from the > > decompressed buffer. But if I use Marshal.from_string to read the > decompressed > > buffer, then I need to keep track of its position (which is not returned > by > > Marshal.from_string), and check whether the buffer is nearly empty, so > that I > > may need to re-read from the compressed in_channel, etc, etc. Did I miss > the > > right function again? > > Marshal has everything you need: > > let input_value ch = > let header = String.create Marshal.header_size > in > Gzip.really_input ch header 0 Marshal.header_size; > let buffer = String.create (Marshal.total_size header 0) > in > Gzip.really_input ch buffer Marshal.header_size (Marshal.data_size > header 0); > String.unsafe_blit header 0 buffer 0 Marshal.header_size; > Marshal.from_string buffer 0 > > > David > --001a1137bdb4efd598050e1ea2fc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Wow, I completely overlooked that. I was convinced that Gz= ip.input/Gzip.really_input returned the number of *compressed* characters r= ead. I misread "uncompresses up to len charact= ers" as "advances the compressed buffer up to len characters"= ;. The phrase "[Gzip.input] returns the actual number of characters re= ad" didn't help me either.

Anyway, thanks a lot, it's m= uch simpler than I expected!




On Mon, Feb 2, 2015 at 6:38 PM, David Alls= opp <dra-news@metastack.com> wrote:
Dhek Uir wrote:
> But since camlzip does not have an input_value function, it seems I mu= st set up
> a buffer to decompress the data, then use Marshal to obtain input data= from the
> decompressed buffer. But if I use Marshal.from_string to read the deco= mpressed
> buffer, then I need to keep track of its position (which is not return= ed by
> Marshal.from_string), and check whether the buffer is nearly empty, so= that I
> may need to re-read from the compressed in_channel, etc, etc. Did I mi= ss the
> right function again?

Marshal has everything you need:

let input_value ch =3D
=C2=A0 let header =3D String.create Marshal.header_size
=C2=A0 in
=C2=A0 =C2=A0 Gzip.really_input ch header 0 Marshal.header_size;
=C2=A0 =C2=A0 let buffer =3D String.create (Marshal.total_size header 0)
=C2=A0 =C2=A0 in
=C2=A0 =C2=A0 =C2=A0 Gzip.really_input ch buffer Marshal.header_size (Marsh= al.data_size header 0);
=C2=A0 =C2=A0 =C2=A0 String.unsafe_blit header 0 buffer 0 Marshal.header_si= ze;
=C2=A0 =C2=A0 =C2=A0 Marshal.from_string buffer 0


David

--001a1137bdb4efd598050e1ea2fc--