Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-03-13 (12:38)
From: Gerd Stolpmann <info@g...>
Subject: Re: [Caml-list] Netclient
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
> "";;
> 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 "" 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

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,


> Thank you,
> JD
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> Archives:
> Beginner's list:
> Bug reports:
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
Phone: +49-6151-153855                  Fax: +49-6151-997714