Have better default opening flags for CCIO.with_{in, out}

This commit is contained in:
Jacques-Pascal Deplaix 2015-05-30 04:54:44 +01:00
parent d98c9cabca
commit 8039ec4db5
2 changed files with 5 additions and 5 deletions

View file

@ -72,7 +72,7 @@ let gen_flat_map f next_elem =
in in
next next
let with_in ?(mode=0o644) ?(flags=[]) filename f = let with_in ?(mode=0o644) ?(flags=[Open_text]) filename f =
let ic = open_in_gen (Open_rdonly::flags) mode filename in let ic = open_in_gen (Open_rdonly::flags) mode filename in
try try
let x = f ic in let x = f ic in
@ -134,7 +134,7 @@ let read_all ?(size=1024) ic =
with Exit -> with Exit ->
Bytes.sub_string !buf 0 !len Bytes.sub_string !buf 0 !len
let with_out ?(mode=0o644) ?(flags=[Open_creat]) filename f = let with_out ?(mode=0o644) ?(flags=[Open_creat; Open_trunc; Open_text]) filename f =
let oc = open_out_gen (Open_wronly::flags) mode filename in let oc = open_out_gen (Open_wronly::flags) mode filename in
try try
let x = f oc in let x = f oc in

View file

@ -48,7 +48,7 @@ Examples:
with_in "/tmp/input" with_in "/tmp/input"
(fun ic -> (fun ic ->
let chunks = read_chunks ic in let chunks = read_chunks ic in
with_out ~flags:[Open_creat; Open_wronly] ~mode:0o644 "/tmp/output" with_out ~flags:[Open_binary] ~mode:0o644 "/tmp/output"
(fun oc -> (fun oc ->
write_gen oc chunks write_gen oc chunks
) )
@ -70,7 +70,7 @@ val with_in : ?mode:int -> ?flags:open_flag list ->
(** Open an input file with the given optional flag list, calls the function (** Open an input file with the given optional flag list, calls the function
on the input channel. When the function raises or returns, the on the input channel. When the function raises or returns, the
channel is closed. channel is closed.
@param flags opening flags (default [[Open_rdonly]]) *) @param flags opening flags (default [[Open_text]]). [Open_rdonly] is used in any cases *)
val read_chunks : ?size:int -> in_channel -> string gen val read_chunks : ?size:int -> in_channel -> string gen
(** Read the channel's content into chunks of size [size] *) (** Read the channel's content into chunks of size [size] *)
@ -94,7 +94,7 @@ val read_all : ?size:int -> in_channel -> string
val with_out : ?mode:int -> ?flags:open_flag list -> val with_out : ?mode:int -> ?flags:open_flag list ->
string -> (out_channel -> 'a) -> 'a string -> (out_channel -> 'a) -> 'a
(** Same as {!with_in} but for an output channel (** Same as {!with_in} but for an output channel
@param flags opening flags (default [[Open_creat; Open_wronly]]) *) @param flags opening flags (default [[Open_creat; Open_trunc; Open_text]]). [Open_wronly] is used in any cases *)
val with_out_a : ?mode:int -> ?flags:open_flag list -> val with_out_a : ?mode:int -> ?flags:open_flag list ->
string -> (out_channel -> 'a) -> 'a string -> (out_channel -> 'a) -> 'a