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: Magesh Kannan <magesh@i...>
Subject: [Caml-list] Question on 'really_input'
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