caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Question on 'really_input'
@ 2002-10-31  2:31 Magesh Kannan
  2002-10-31 11:53 ` Bruno.Verlyck
  0 siblings, 1 reply; 2+ messages in thread
From: Magesh Kannan @ 2002-10-31  2:31 UTC (permalink / raw)
  To: caml-list

Hi All,

I am writing a program that reads a file using multiple reads of a fixed 
size chunk. I tried using 'input' but input can read fewer bytes than
requested (and frequently does so; the ocaml implementation seems to read
4K blocks from the disk and if an 'input' call spans this boundary, the 
bytes left in the first block are returned, even if their length is less
than the requested length). 'really_input' seems to be a nice alternative
to do this, but there is a small problem.

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. Is this correct? If not, how do I find out how many bytes were
actually read? I cannot use String.length here, because it returns the
allocated length and not what is being used.

Can 'really_input' be used for such purposes? I can implement the behavior
of 'really_input' with the variation I am looking for, by running 'input' 
in a loop, but I wanted to make sure there is no built-in solution. BTW, I
have to read the file in fixed size chunks (and cannot issue a single read
using 'really_input' for the file's total size).

Thanks for your help,
Magesh

-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Question on 'really_input'
  2002-10-31  2:31 [Caml-list] Question on 'really_input' Magesh Kannan
@ 2002-10-31 11:53 ` Bruno.Verlyck
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno.Verlyck @ 2002-10-31 11:53 UTC (permalink / raw)
  To: magesh; +Cc: caml-list

   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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-31 11:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-31  2:31 [Caml-list] Question on 'really_input' Magesh Kannan
2002-10-31 11:53 ` Bruno.Verlyck

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).