caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Stéphane Glondu" <steph@glondu.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] wrapping a string in an in_channel
Date: Tue, 07 Jan 2014 22:02:10 +0100	[thread overview]
Message-ID: <52CC6B52.3000808@glondu.net> (raw)
In-Reply-To: <CAFrFfuGJ1RfPo9vOx_psAszQO-Lq=J351qC+TGeWAZzv+=aJCQ@mail.gmail.com>

Le 05/01/2014 09:23, Martin DeMello a écrit :
> Does OCaml have any equivalent to ruby's StringIO, to wrap an
> in_channel around a string and then treat it as if it were a file?

Technically, it should be possible by using low-level Unix machinery
like in the following:

let wrap_string s =
  let infd, outfd = Unix.pipe () in
  let inc = Unix.in_channel_of_descr infd in
  let outc = Unix.out_channel_of_descr outfd in
  let writer () =
    output_string outc s;
    flush outc;
    close_out outc
  in Thread.create writer ();
  inc

... but the other suggestions are probably better...

Cheers,

-- 
Stéphane


      parent reply	other threads:[~2014-01-07 21:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-05  8:23 Martin DeMello
2014-01-05  9:49 ` Gerd Stolpmann
2014-01-05 14:23 ` Hezekiah M. Carty
2014-01-06 10:32 ` John Whitington
2014-01-07 21:02 ` Stéphane Glondu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52CC6B52.3000808@glondu.net \
    --to=steph@glondu.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).