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: Goswin von Brederlow <goswin-v-b@w...>
Subject: Re: [Caml-list] Buffer.add_channel hangs
Stas Miasnikou <stas.miasnikou@gmail.com> writes:

> Hi,
>
> 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?
>
> Stas

For the problem see the other mail.

For a better solution I suggest you look at the Bigarray module. You can
mmap your file as int8_unsigned array and have your read_file function
done all in simple step.

MfG
        Goswin