Import std.io.file_stream
std.io.file_stream
std.io's open files: File.Open gives a FileStream, a Reader, Writer, and Seeker over a file, which reads and writes where it is, as Seek moves it, with Async twins that libuv's thread pool does while the main thread goes on.
std/io/file_stream.fb
Types
OpenOptions
struct
Public Struct OpenOptions
How File.Open opens a file: to read, to write, or both, and, for one it writes, whether each write goes at its end, whether it's made when it isn't there, or only then, and whether what it held is gone first.
std/io/file_stream.fb, line 36
-
Whether it reads the file.
-
Whether it writes the file.
-
Each write goes at the file's end, wherever the stream is, which is a write too.
-
The file is made, empty, when it isn't there.
-
The file is made, and one that's there is an IOError of ALREADY_EXISTS.
-
What the file held is gone once it's open.
FileStream
class
Public Class FileStream Implements Reader, Writer, Seeker
A file opened to read, write, or both, at a place in it that each read and write moves on, and Seek moves anywhere, until it's closed, or its last reference goes. It holds nothing back, so Flush has nothing to do, and Sync puts what's been written onto the disk. A BufferedReader or a BufferedWriter around it takes fewer calls for small reads and writes. One call at a time goes on it: a call while an Async one is under way panics, and so does using it once it's closed, reading one not opened to read, and writing one not opened to write.
std/io/file_stream.fb, line 78
-
The file it's open on.
-
Whether it was opened to read.
-
Whether it was opened to write.
-
Whether each write goes at the end.
-
Whether it's still open.
-
Reads up to into.Count bytes from where it is, and moves on past them.
-
Read's Async twin, which waits on the main thread instead of blocking it. One that can only block reads with Read.
Doc from
std.io.streams.Reader.ReadAsync. -
Writes all of from's bytes where it is, or at the end when it appends, and moves on past them.
-
Write's Async twin, which waits on the main thread instead of blocking it.
Doc from
std.io.streams.Writer.WriteAsync. -
Holds nothing back, so there's nothing to send on, but it panics once it's closed too.
-
Flush's Async twin.
Doc from
std.io.streams.Writer.FlushAsync. -
Puts what's been written to the file onto the disk, as File's atomic writes do theirs, so it's there even if the machine stops. One not opened to write has nothing to put there.
-
What Sync does, without blocking its thread: a call gives its Task.
-
@PanicsAtCaller Public Method Seek(offset: Int64, origin: SeekOrigin): Int64 Throws IOErrormethod #Moves to
offsetbytes fromorigin, as Seeker says, where the next read reads and the next write writes, unless it appends. A place past the end is where a write makes the file longer, with 0s before it. -
How many bytes the file has now.
-
Closes the file, which a second Close leaves alone. What was written stays in the file, for the OS to put onto the disk.
Report an issue with this page or with FutureBlitz on GitHub.