(will be removed after 1.0.0) Use the Web Streams API instead.
Writer utility for buffering string chunks.
Examples
Example 1
Example 1
import { copyN, StringReader, StringWriter, } from "@std/io"; import { copy } from "@std/io/copy"; const w = new StringWriter("base"); const r = new StringReader("0123456789"); await copyN(r, w, 4); // copy 4 bytes // Number of bytes read console.log(w.toString()); //base0123 await copy(r, w); // copy all console.log(w.toString()); // base0123456789
Output:
base0123 base0123456789
Constructors
new StringWriter(base?: string)Methods
write(p: Uint8Array): Promise<number>Writes p.byteLength bytes from p to the underlying data stream. It
resolves to the number of bytes written from p (0 <= n <=
p.byteLength) or reject with the error encountered that caused the
write to stop early. write() must reject with a non-null error if
would resolve to n < p.byteLength. write() must not modify the
slice data, even temporarily.
Implementations should not retain a reference to p.
writeSync(p: Uint8Array): numberWrites p.byteLength bytes from p to the underlying data
stream. It returns the number of bytes written from p (0 <= n
<= p.byteLength) and any error encountered that caused the write to
stop early. writeSync() must throw a non-null error if it returns n <
p.byteLength. writeSync() must not modify the slice data, even
temporarily.
Implementations should not retain a reference to p.