Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Question on 'really_input'
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bruno.Verlyck@i...
Subject: Re: [Caml-list] Question on 'really_input'
   Date: Wed, 30 Oct 2002 20:31:33 -0600 (CST)
   From: Magesh Kannan <magesh@ittc.ku.edu>

   During the last read from the file, if the number of bytes in the
   file is less than the requested length, 'really_input' reads
   whatever is available and also raises an exception, because EOF has
   been reached.  But there seems to be no way to find out how many
   bytes were actually read in this operation. [..]

   Can 'really_input' be used for such purposes?
Yes, no.  I understand that really_input is more useful with pipes, or
anything having no predefined size, but one can imagine workarounds
for your problem; e.g., you can get the current position with pos_in
before each really_input, then, on End_of_file, use seek_in and
String.length (input ..).  You can also compute the number of full
chunks in the file (the number of remaining bytes) by dividing (taking
the modulus of) the file size (in_channel_length) by the chunk size.

   I can implement the behavior of 'really_input' with the variation I
   am looking for, by running 'input' in a loop, but [..]
This is an equally good solution, given that really_input works by
looping too.

Bruno.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners