25 |
let cont = ref true in |
let cont = ref true in |
26 |
let rec iter buf nb_read = |
let rec iter buf nb_read = |
27 |
let buf_size = String.length buf in |
let buf_size = String.length buf in |
28 |
let to_read = min (buf_size - nb_read) 10000 in |
let to_read = min (buf_size - nb_read) 8192 in |
29 |
let tmp = input chan buf nb_read to_read in |
let tmp = input chan buf nb_read to_read in |
30 |
if tmp = 0 then |
if tmp = 0 then |
31 |
String.sub buf 0 nb_read |
String.sub buf 0 nb_read |
41 |
let buf = iter buf 0 in |
let buf = iter buf 0 in |
42 |
close_in chan; |
close_in chan; |
43 |
buf |
buf |
44 |
|
|
45 |
|
let read_whole_chan chan = |
46 |
|
let buf = Buffer.create 1024 in |
47 |
|
let rec loop () = |
48 |
|
Buffer.add_char buf (input_char chan); |
49 |
|
loop () |
50 |
|
in |
51 |
|
try |
52 |
|
loop () |
53 |
|
with |
54 |
|
End_of_file -> close_in chan; buf |
55 |
|
|
56 |
|
let to_string_alt name = |
57 |
|
let chan = open_in_bin name in |
58 |
|
read_whole_chan chan |
59 |
|
|
60 |
|
let to_copy in_name out_name = |
61 |
|
let in_chan = open_in_bin in_name and |
62 |
|
out_chan = open_out_bin out_name in |
63 |
|
try |
64 |
|
let rec rcpy () = |
65 |
|
let c = input_byte in_chan in |
66 |
|
output_byte out_chan c; |
67 |
|
flush out_chan; |
68 |
|
rcpy (); |
69 |
|
in |
70 |
|
rcpy () |
71 |
|
with |
72 |
|
End_of_file -> () |
73 |
|
|
74 |
let from_string name s = |
let from_string name s = |
75 |
let oc = open_out name in |
let oc = open_out name in |
76 |
output_string oc s; |
output_string oc s; |