From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9847FBBBB for ; Mon, 13 Mar 2006 13:38:34 +0100 (CET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.191]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k2DCcYX9018179 for ; Mon, 13 Mar 2006 13:38:34 +0100 Received: from [212.227.126.160] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1FImJS-0003PY-00; Mon, 13 Mar 2006 13:38:14 +0100 Received: from [84.58.142.103] (helo=gate.lan.gerd-stolpmann.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1FImJS-0003eA-00; Mon, 13 Mar 2006 13:38:14 +0100 Received: from flakew.lan.gerd-stolpmann.de (flakew.lan.gerd-stolpmann.de [192.168.0.32]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id 87F8CC094; Mon, 13 Mar 2006 13:38:14 +0100 (CET) Subject: Re: [Caml-list] Netclient From: Gerd Stolpmann To: jean-david@GameBox.net Cc: caml-list@yquem.inria.fr In-Reply-To: <20060313080325.40774.qmail@web38209.mail.mud.yahoo.com> References: <20060313080325.40774.qmail@web38209.mail.mud.yahoo.com> Content-Type: text/plain Date: Mon, 13 Mar 2006 13:38:14 +0100 Message-Id: <1142253494.11735.29.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:a6865a839c0178d9aa0ce41878507ea2 X-Miltered: at nez-perce with ID 441567CA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; netclient:01 gerd:01 stolpmann:01 fulfils:01 netclient:01 invokes:01 netchannel:01 event-driven:01 non-trivial:01 gerd:01 beginner's:01 ocaml:01 beginners:01 bug:01 stolpmann:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Am Montag, den 13.03.2006, 00:03 -0800 schrieb Jean-David: > Hello there, > I was wondering about the best way to create a stream > from a remote file for which I have the URL > > open Http_client > open Stream > > let body = Stream.of_string Convenience.http_get > "http://dfl.sjsu.edu";; > > Is the content of body downloaded completely before > being streamed(which defeats the purpose of streams) > or not? and if not how can I get the content of an URL > gradually (without getting the whole body into > memory)? Yes, Convenience.http_get always downloads the whole body into a string. For a stream-like download, you must use the pipeline interface. For example, to store the body into a file do: let call = new get "http://dfl.sjsu.edu" in call # set_response_body_storage (`File (fun () -> "filename")); let pipeline = new pipeline in pipeline # set_proxy_from_environment(); pipeline # run() Now check call#status whether the HTTP request was successfully responded. If you want to postprocess the body while it is downloaded, things will get more complicated. In particular, it is possible to store the body in an object that fulfils the Netmime.mime_body class type. Netclient invokes the open_value_wr method and outputs into this netchannel. Using this mechanism to define a callback-style interface (i.e. a function is called whenever a chunk of data arrives) can be implemented in a straight-forward manner. If you really need a "string Stream.t": This is possible because Netclient is programmed in an event-driven way, but is very difficult, because you must arrange a so-called control inversion. This is absolutely non-trivial but implementable in less than 100 lines of code. Hope this helps, Gerd > > Thank you, > JD > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------