123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181(*
include In_channel
*)(*
let max_buffer_size = 0x1000000
let input_and_copy_to_bigarray channel buffer tgt pos len =
let read = input channel buffer 0 len in
for i = 0 to read - 1 do
Bigarray.Array1.unsafe_set tgt (pos + i) (int_of_char (Bytes.unsafe_get buffer i))
done;
read
let rec input_and_copy_to_bigarray_loop channel buffer tgt pos len already_read =
let buffer_length = Bytes.length buffer in
if buffer_length < len then
begin
let read =
input_and_copy_to_bigarray channel buffer tgt pos buffer_length in
let already_read = already_read + read in
if read = buffer_length then
input_and_copy_to_bigarray_loop channel buffer tgt (pos + read)
(len - read) already_read
else
already_read
end
else
begin
let read = input_and_copy_to_bigarray channel buffer tgt pos len in
already_read + read
end
let input_bigarray channel tgt pos len =
if len < 0 || pos + len >= Bigarray.Array1.dim tgt then
invalid_arg "input_bigarray";
let buffer_size = min max_buffer_size len in
let buffer = Bytes.create buffer_size in
input_and_copy_to_bigarray_loop channel buffer tgt pos len 0
let really_input_bigarray channel tgt pos len =
if len < 0 || pos + len >= Bigarray.Array1.dim tgt then
invalid_arg "input_bigarray";
let buffer_size = min max_buffer_size len in
let buffer = Bytes.create buffer_size in
let rec loop len =
let read = input_and_copy_to_bigarray_loop channel buffer tgt pos len 0 in
if read = 0 then
None
else if read < len then
Some ()
else
loop (len - read) in
loop len
*)letinput_bigarray_channel_tgt_pos_len=failwith"input_bigarray"letreally_input_bigarray_channel_tgt_pos_len=failwith"really_input_bigarray"letis_binary_mode_channel=failwith"is_binary_mode"typet=in_channeltypeopen_flag=Pervasives.open_flag=Open_rdonly|Open_wronly|Open_append|Open_creat|Open_trunc|Open_excl|Open_binary|Open_text|Open_nonblockletstdin=stdinletopen_bin=open_in_binletopen_text=open_inletopen_gen=open_in_genletread_and_closechannelf=Stdcompat__fun.protect~finally:(fun()->close_in_noerrchannel)(fun()->fchannel)letwith_open_binfilenamef=read_and_close(open_binfilename)fletwith_open_textfilenamef=read_and_close(open_textfilename)fletwith_open_genflagspermfilenamef=read_and_close(open_genflagspermfilename)fletseek=LargeFile.seek_inletpos=LargeFile.pos_inletlength=LargeFile.in_channel_lengthletclose=close_inletclose_noerr=close_in_noerrletinput_charic=trySome(input_charic)withEnd_of_file->Noneletinput_byteic=trySome(input_byteic)withEnd_of_file->Noneletinput_lineic=trySome(input_lineic)withEnd_of_file->Noneletinput=inputletreally_inputicbufposlen=tryreally_inputicbufposlen;Some()withEnd_of_file->Noneletreally_input_stringiclen=trySome(Stdcompat__pervasives.really_input_stringiclen)withEnd_of_file->Noneletset_binary_mode=set_binary_mode_inletrecadd_channel_to_the_end~chunk_sizebufferchannel=iftryStdcompat__buffer.add_channelbufferchannelchunk_size;truewithEnd_of_file->falsethenadd_channel_to_the_end~chunk_sizebufferchannelletinput_allchannel=letchunk_size=65536inletbuffer_size=tryin_channel_lengthchannel-pos_inchannelwithSys_error_->-1inletbuffer=Buffer.createbuffer_sizeinadd_channel_to_the_end~chunk_sizebufferchannel;Buffer.contentsbufferletrecfold_linesfaccic=matchinput_lineicwith|None->acc|Someline->fold_linesf(faccline)icletinput_linesic=List.rev(fold_lines(funaccline->line::acc)[]ic)letisatty_ic=failwith"not implemented"