Open a file for buffered writing. The WriteMode decides whether
existing data survives, so it has no default.
Failing to open reports the path, as [File.open_reader!] does.
Prefer [File.with_writer!]: with a writer opened here, a ? on a write
returns before the final flush!, and the failure
of the flush that happens on release is not reported.
The file is closed when the last reference to the reader is released.
Copies of a reader share one cursor and one buffer, so every read,
whether of lines, delimited bytes or binary data, continues where the
previous one stopped.
Every read ends the same way: once all data has been returned, the next
read is Err(EndOfInput). An empty Ok is real data, such as an empty
line. A read may be repeated after EndOfInput; if the file has grown
it returns the new data.
Read at most max_bytes bytes. Short reads are valid, even before
the end of the file. Asking for zero bytes performs no I/O and
returns Ok([]); otherwise the result is never empty, and the end
of the file is Err(EndOfInput).
Returned bytes remain valid after later reads or seeks.
Read exactly count bytes, or report UnexpectedEndOfInput.
Zero succeeds without I/O. Errors may consume bytes; partial data is
not returned and the cursor is not restored.
Read bytes through and including the next delimiter.
If the file ends first, the bytes before the end are returned without
a delimiter, and the read after that is Err(EndOfInput). So the
result is never empty, and its last byte shows whether the delimiter
arrived: to follow a growing file line by line, use
reader.read_until!('\n') rather than [read_line!].
A line ends at \n. The terminator is not returned, and one \r
before it is removed. A file that ends without a \n still yields
its last line; after that the result is Err(EndOfInput). An empty
line is Ok(""). Lines have no length limit.
A line that is not valid UTF-8 is consumed and reported as BadUtf8;
the next call reads the line after it. For the bytes of a line, use
reader.read_until!('\n').
Move the shared cursor and return its new absolute byte position.
Seeking past EOF does not extend the file. Invalid offsets and sources
that cannot seek report FileErr. A failed seek need not restore the cursor.
Aliases of this reader observe the same cursor.
Lazily read this reader a line at a time, as [read_line!] does.
Building the stream reads nothing. The stream ends at the end of the
file. A BadUtf8 item concerns one line, and the stream continues
with the next. A FileErr item is the last one; the reader stays
usable and a new stream may be started.
Each item is one read from the shared cursor and the stream holds no
data of its own, so it can be mixed with [seek!], [position!] and
the other reads, and leaving the loop early loses nothing.
Lazily read this reader as non-empty chunks of at most 64 KiB.
Chunk boundaries do not correspond to records, newlines, or text
encoding boundaries. For a chosen size, call [read_up_to!] in a loop.
Building the stream reads nothing; each item is one read from the
shared cursor. The stream ends at the end of the file. A FileErr
item is the last one; the reader stays usable and a new stream may be
started, for example after a [seek!]. Retained chunks remain valid.
The stream keeps the file open until it has finished or is released.
Process chunks individually to bound memory; Stream.collect!
accumulates every chunk.
Written bytes are held in a buffer in the host and reach the operating
system when the buffer fills and on [flush!]. A write accepts all of
its bytes or fails. Copies of a writer share one file and one buffer.
There is no close!: the file is closed when the last reference to the
writer is released. Bytes still buffered then are written, but a
failure to write them cannot be reported, so call [flush!] after the
last write, or use [File.with_writer!], which does it for you.
Write each chunk of a stream as it arrives, holding one chunk in
memory at a time.
Stops at the first Err item, which is returned as SourceErr; the
chunks before it have been written. A failed write is FileErr.
Nothing is flushed at the end.
Any stream of byte chunks will do: reader.chunks(),
Stdin.chunks(), the response.chunks() of an
Http.send_streaming! response, or a stream
mapped from one of them.