mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
Have better default opening flags for CCIO.with_{in, out}
This commit is contained in:
parent
d98c9cabca
commit
8039ec4db5
2 changed files with 5 additions and 5 deletions
|
|
@ -72,7 +72,7 @@ let gen_flat_map f next_elem =
|
|||
in
|
||||
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
|
||||
try
|
||||
let x = f ic in
|
||||
|
|
@ -134,7 +134,7 @@ let read_all ?(size=1024) ic =
|
|||
with Exit ->
|
||||
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
|
||||
try
|
||||
let x = f oc in
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ Examples:
|
|||
with_in "/tmp/input"
|
||||
(fun ic ->
|
||||
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 ->
|
||||
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
|
||||
on the input channel. When the function raises or returns, the
|
||||
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
|
||||
(** 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 ->
|
||||
string -> (out_channel -> 'a) -> 'a
|
||||
(** 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 ->
|
||||
string -> (out_channel -> 'a) -> 'a
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue