Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.
Example: copy a file "a" into file "b", removing blank lines:
Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;
Read the lines of a file into a list:
Iterator.IO.lines "a" |> Iterator.to_list
since 0.5.1
Sourceval lines_of : ?mode:int ->?flags:open_flag list->string ->string t
lines_of filename reads all lines of the given file. It raises the same exception as would opening the file and read from it, except from End_of_file (which is caught). The file is always properly closed. Every time the iterator is iterated on, the file is opened again, so different iterations might return different results
parametermode
default 0o644
parameterflags
default: [Open_rdonly]
Sourceval chunks_of :
?mode:int ->?flags:open_flag list->?size:int ->string ->string t
Read chunks of the given size from the file. The last chunk might be smaller. Behaves like lines_of regarding errors and options. Every time the iterator is iterated on, the file is opened again, so different iterations might return different results
Sourceval write_to : ?mode:int ->?flags:open_flag list->string ->string t-> unit
write_to filename seq writes all strings from seq into the given file. It takes care of opening and closing the file.
parametermode
default 0o644
parameterflags
used by open_out_gen. Default: [Open_creat;Open_wronly].