Re: [Caml-list] in and out channels into memory

2 views
Skip to first unread message

Richard Jones

unread,
Jul 10, 2006, 5:52:42 AM7/10/06
to Jim Miller, caml...@yquem.inria.fr
On Sun, Jul 09, 2006 at 09:53:29PM -0400, Jim Miller wrote:
> Is there a way in OCaml to read and write into memory using in and out
> channels in the standard distribution? It seems like there are functions
> for converting everything else to in and out channels but I can't seem to
> find anything for writing into and out of memory. If there isn't something
> already, is there a function for creating new in and out channels?

Not for the in/out_channel in the standard distribution.

However if you can change the code to use the IO class types defined
here (http://www.ocaml-programming.de/rec/IO-Classes.html) then you
can use something like input_string from the Netstring library:

let s = "1\n2\n3\n4" in
let ch = new input_string s in
ch#input_line ()

If you can't change the code, then the best you can do might be to
read and write a temporary file (see: Filename.open_temp_file).

Another alternative from the std lib is Buffer, but that also requires
changing the code.

Rich.

--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.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

Reply all
Reply to author
Forward
0 new messages