Import std.io.buffered
std.io.buffered
Buffered readers and writers over other streams.
Buffered streams: BufferedReader reads another Reader a buffer at a time, so that many small reads, a byte or a line at a time, cost one of its; BufferedWriter writes another Writer a buffer at a time. Their Async twins go through the other stream's.
std/io/buffered.fb
Types
BufferedReader
class
Public Class BufferedReader Implements Reader
Reads another Reader a buffer's bytes at a time, and gives them as they're asked for, a byte or a line at a time too.
Examples
Local reader = BufferedReader(StringReader("one\r\ntwo\nlast"))
Expect((Try reader.ReadLine()) == "one")
Expect((Try reader.ReadLine()) == "two")
Expect((Try reader.ReadLine()) == "last")
Expect((Try reader.ReadLine()) == Null)-
Reads
innersizebytes at a time. Panics whensizeis below 1. -
As many as it has of what's next, or a read of the other Reader's. One for a whole buffer or more goes straight to the other Reader when it has none.
-
Read's Async twin: what it has of what's next, or what an Async read of the other Reader gives, while the main thread goes on.
-
The next byte, or Null once the stream has ended.
-
ReadByte's Async twin, through the other Reader's ReadAsync.
-
The next line, without the \n or \r\n that ends it, or Null once the stream has ended. A last line without one is a line too. When the other Reader throws, what it had of the line waits for the next ReadLine, which goes on with it.
-
ReadLine's Async twin, through the other Reader's ReadAsync.
BufferedWriter
class
Public Class BufferedWriter Implements Writer
Writes another Writer a buffer's bytes at a time: what's written waits in a buffer until a write doesn't fit what's left of it, or Flush sends it on. What's still waiting when it goes is written then, without the errors that Flush would give.
Examples
Local memory = MemoryStream()
Local writer = BufferedWriter(memory, 64)
Try writer.WriteText("held ")
Try writer.WriteText("back")
Expect(memory.Count == 0)
Try writer.Flush()
Expect(String.FromUtf8(memory.ToArray()) == "held back")-
Writes
innersizebytes at a time. Panics whensizeis below 1. -
Keeps the bytes, sending on what waits first when they don't fit what's left of the buffer. A write of a whole buffer or more goes straight to the other Writer, after what waits.
-
Write's Async twin, which sends on what waits by the other Writer's WriteAsync when the bytes don't fit.
-
Sends on what waits, and flushes the other Writer.
-
Flush's Async twin: sends on what waits, and flushes the other Writer, while the main thread goes on.
Report an issue with this page or with FutureBlitz on GitHub.