Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
RedirectSourceread_and_close chan f evaluates f (), then closes chan and returns the value computed by the evaluation of f. chan is close even if f raises an exception. The difference between read_and_close chan f and Fun.protect f ~finally:(fun () -> close_in chan) is that if f () succeeds and close_in chan raises an exception, this exception is not intercepted, and if f () raises an exception, then close_in_noerr is used so that the exception raised by f () is not masked.
write_and_close chan f evaluates f (), then closes chan and returns the value computed by the evaluation of f. chan is close even if f raises an exception. The difference between write_and_close chan f and Fun.protect f ~finally:(fun () -> close_out chan) is that if f () succeeds and close_out chan raises an exception, this exception is not intercepted, and if f () raises an exception, then close_out_noerr is used so that the exception raised by f () is not masked.
val add_channel_to_the_end :
?chunk_size:int ->
Stdcompat.Buffer.t ->
Stdcompat.in_channel ->
unitadd_channel_to_the_end ~chunk_size buf chan reads chan up to reaching end of file and adds the contents read to buf. chan is read by blocks of chunk_size bytes, 1024 by default.
val output_channel_to_the_end :
?chunk_size:int ->
Stdcompat.out_channel ->
Stdcompat.in_channel ->
unitoutput_channel_to_the_end ~chunk_size out_chan in_chan reads in_chan up to reaching end of file and outputs the contents read to out_chan. in_chan is read by blocks of chunk_size bytes, 1024 by default.
output_file ~chunk_size out_chan filename outputs the contents of the file filename to out_chan. The file is read by blocks of chunk_size bytes, 1024 by default.
output_file ~chunk_size source target copies the file source into the file target. The file is read by blocks of chunk_size bytes, 1024 by default.
val with_temp_file :
?prefix:string ->
?suffix:string ->
string ->
(string -> Stdcompat.in_channel -> 'a) ->
'awith_temp_file ~prefix ~suffix contents f creates a temporary file with a fresh filename forged from prefix and suffix (by calling Filename.open_temp_file), outputs contents in it, opens this file for reading as channel, and evaluates f filename channel. Once f returns or raises an exception, channel is closed and the file is removed. If f succeeds, the returned value is the value computed by f. If f raises an exception, this exception is raised again.
with_pipe f creates a Unix pipe (in_chan, out_chan) and evaluates f in_chan out_chan. Channels are closed even if f raises an exception.
with_stdin_from chan f evaluates f () by redirecting chan to the standard input. The former standard input is restored afterwards, even if f raises an exception.
with_stdout_from chan f evaluates f () by redirecting the standard output to chan. The former standard output is restored afterwards, even if f raises an exception.
with_channel_from_string s f evaluates f chan where chan is a channel from which s can be read.
val with_channel_to_buffer :
?chunk_size:int ->
Stdcompat.Buffer.t ->
(Stdcompat.out_channel -> 'a) ->
'awith_channel_to_buffer buf f evaluates f chan where chan is a channel, such that the contents written to it is added to buf.
val with_channel_to_string :
?initial_size:int ->
?chunk_size:int ->
(Stdcompat.out_channel -> 'a) ->
string * 'awith_channel_to_string f evaluates f chan where chan is a channel, and returns (s, v) where s is the contents written to chan and v is the value computed by f.
with_stdin_from_string s f evaluates f () by redirecting the standard input such that s can be read from it.
with_stdout_to_buffer buf f evaluates f () by redirecting the standard output such that the contents written to it is added to buf.
val with_stdout_to_string :
?initial_size:int ->
?chunk_size:int ->
(unit -> 'a) ->
string * 'awith_channel_to_string f evaluates f () by redirecting the standard output and returns (s, v) where s is the contents written to the standard output and v is the value computed by f.