Legend:
Library
Module
Module type
Parameter
Class
Class type
IO Utils
Simple utilities to deal with basic Input/Output tasks in a resource-safe way. For advanced IO tasks, the user is advised to use something like Lwt or Async, that are far more comprehensive.
NOTE this was formerly a monadic IO module. The old module is now in containers.advanced under the name CCMonadIO.
Examples:
obtain the list of lines of a file:
# let l = CCIO.(with_in "/tmp/some_file" read_lines);;
transfer one file into another:
# CCIO.(
with_in "/tmp/input"
(fun ic ->
let chunks = read_chunks ic in
with_out ~flags:[Open_creat; Open_wronly] ~mode:0o644 "/tmp/output"
(fun oc ->
write_gen oc chunks
)
)
) ;;
since 0.6
type'a gen = unit ->'a option
See Gen
Input
val with_in :
?mode:int ->?flags:Pervasives.open_flag list->string ->(Pervasives.in_channel ->'a)->'a
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.
val read_chunks : ?size:int ->Pervasives.in_channel ->string gen
Read the channel's content into chunks of size size
val read_line : Pervasives.in_channel ->string option
Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.
val read_lines : Pervasives.in_channel ->string gen
Read all lines. The generator should be traversed only once.
val read_lines_l : Pervasives.in_channel ->string list
Read all lines into a list
val read_all : ?size:int ->Pervasives.in_channel -> string
Read the whole channel into a buffer, then converted into a string.
parametersize
the internal buffer size
@since 0.7
Output
val with_out :
?mode:int ->?flags:Pervasives.open_flag list->string ->(Pervasives.out_channel ->'a)->'a