Version française
Home     About     Download     Resources     Contact us    
Browse thread
Buffer.add_channel hangs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stas Miasnikou <stas.miasnikou@g...>
Subject: Re: Buffer.add_channel hangs
On 3/18/10, Stas Miasnikou <stas.miasnikou@gmail.com> wrote:
> On 3/17/10, Stas Miasnikou <stas.miasnikou@gmail.com> wrote:
>> OCaml 3.11.1, OpenBSD 4.6, i386.
>>
>> I am trying to read whole file by doing:
>>
>> let read_file_bin name =
>>   let ic = open_in_bin name in
>>   let b = Buffer.create 1024 in
>>   (try Buffer.add_channel b ic max_int with _ -> ()); (* <-- HERE *)
>>   close_in ic;
>>   Array.init (Buffer.length b) (fun i -> int_of_char (Buffer.nth b i))
>>
>> but it hangs on the line marked. Am I doing something wrong?
>
> More on this, when doing:
>
> let read_file_bin name =
>   let ic = open_in_bin name in
>   let b = Buffer.create 1024 in
>   (try Buffer.add_channel b ic (n + 100) with _ -> ());
>   close_in ic;
>   print_int (Buffer.length b); print_newline ();
>   Array.init (Buffer.length b) (fun i -> int_of_char (Buffer.nth b i))
>
> With file length equal to n (65536) I get nothing read, i.e. after
> reading Buffer.length b returns 0. Can anyone check this, so I know
> whether this is OCaml or my OpenBSD 4.6 port of it issue?

Aha, this behaviour is documented, mea culpa.

Stas