//@NO-IMPLICIT-PRELUDE
//! Functions for working with I/O
let io_prim @ { IO, File } = import! std.io.prim
let { Read } = import! std.io.read
let { Write } = import! std.io.write
let { Disposable } = import! std.disposable
let { functor, applicative, monad } = import! std.io.base
/// Opens the file at `path` in read-only mode. Fails if the file does not
/// exist.
let open_file path : String -> IO File =
let { OpenOptions } = io_prim
io_prim.open_file_with path [Read]
/// Opens a file in write-only mode. If the file already exists, it will be
/// truncated. If the file does not exist, it will be created.
let create_file path : String -> IO File =
let { OpenOptions } = io_prim
io_prim.open_file_with path [Create, Write, Truncate]
let read : Read File = {
read = io_prim.read_file,
read_to_end = io_prim.read_file_to_end,
}
let write : Write File = {
write_slice = io_prim.write_slice_file,
flush = io_prim.flush_file,
}
let disposable : Disposable File = {
dispose = io_prim.close_file,
is_disposed = io_prim.is_file_closed,
}
{
open_file,
create_file,
functor,
applicative,
monad,
read,
write,
disposable,
..
io_prim
}