Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
UNSTABLE: The utilities for advanced I/O operations using Reader and Writer interfaces.
Classes
A variable-sized buffer of bytes with read() and write() methods.
- bytes(options?: { copy: boolean; }): Uint8Array
Returns a slice holding the unread portion of the buffer.
- capacity(): number
The read only capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.
- empty(): boolean
Returns whether the unread portion of the buffer is empty.
- grow(n: number): void
Grows the buffer's capacity, if necessary, to guarantee space for another
nbytes. After.grow(n), at leastnbytes can be written to the buffer without another allocation. Ifnis negative,.grow()will throw. If the buffer can't grow it will throw an error. - length(): number
A read only number of bytes of the unread portion of the buffer.
- read(p: Uint8Array): Promise<number | null>
Reads the next
p.lengthbytes from the buffer or until the buffer is drained. Resolves to the number of bytes read. If the buffer has no data to return, resolves to EOF (null). - readFrom(r: Reader): Promise<number>
Reads data from
runtil EOF (null) and appends it to the buffer, growing the buffer as needed. It resolves to the number of bytes read. If the buffer becomes too large,.readFrom()will reject with an error. - readFromSync(r: ReaderSync): number
Reads data from
runtil EOF (null) and appends it to the buffer, growing the buffer as needed. It returns the number of bytes read. If the buffer becomes too large,.readFromSync()will throw an error. - readSync(p: Uint8Array): number | null
Reads the next
p.lengthbytes from the buffer or until the buffer is drained. Returns the number of bytes read. If the buffer has no data to return, the return is EOF (null). - reset(): void
Resets the contents
- truncate(n: number): void
Discards all but the first
nunread bytes from the buffer but continues to use the same allocated storage. It throws ifnis negative or greater than the length of the buffer. - write(p: Uint8Array): Promise<number>
Writes the given data to the buffer. Resolves to the number of bytes written.
- writeSync(p: Uint8Array): number
Writes the given data to the buffer.
Enums
A enum which defines the seek mode for IO related APIs that support seeking.
Functions
Copies from src to dst until either EOF (null) is read from src or
an error occurs. It resolves to the number of bytes copied or rejects with
the first error encountered while copying.
Turns a Reader into an async iterator.
Turns a ReaderSync into an iterator.
Read Reader r until EOF (null) and resolve to the content as
Uint8Array.
Synchronously reads ReaderSync r until EOF (null) and returns
the content as Uint8Array.
Create a Reader from a ReadableStreamDefaultReader.
Create a ReadableStream of Uint8Arrays from a
Reader.
Create a WritableStream from a Writer.
Write all the content of the array buffer (arr) to the writer (w).
Synchronously write all the content of the array buffer (arr) to the
writer (w).
Interfaces
An abstract interface which when implemented provides an interface to close files/resources that were previously opened.
- close(): void
Closes the resource, "freeing" the backing file/resource.
An abstract interface which when implemented provides an interface to read bytes into an array buffer asynchronously.
- read(p: Uint8Array): Promise<number | null>
Reads up to
p.byteLengthbytes intop. It resolves to the number of bytes read (0<n<=p.byteLength) and rejects if any error encountered. Even ifread()resolves ton<p.byteLength, it may use all ofpas scratch space during the call. If some data is available but notp.byteLengthbytes,read()conventionally resolves to what is available instead of waiting for more.
An abstract interface which when implemented provides an interface to read bytes into an array buffer synchronously.
- readSync(p: Uint8Array): number | null
Reads up to
p.byteLengthbytes intop. It resolves to the number of bytes read (0<n<=p.byteLength) and rejects if any error encountered. Even ifread()returnsn<p.byteLength, it may use all ofpas scratch space during the call. If some data is available but notp.byteLengthbytes,read()conventionally returns what is available instead of waiting for more.
An abstract interface which when implemented provides an interface to seek within an open file/resource asynchronously.
- seek(): Promise<number>offset: number | bigint,whence: SeekMode
Seek sets the offset for the next
read()orwrite()to offset, interpreted according towhence:Startmeans relative to the start of the file,Currentmeans relative to the current offset, andEndmeans relative to the end. Seek resolves to the new offset relative to the start of the file.
An abstract interface which when implemented provides an interface to seek within an open file/resource synchronously.
- seekSync(): numberoffset: number | bigint,whence: SeekMode
Seek sets the offset for the next
readSync()orwriteSync()to offset, interpreted according towhence:Startmeans relative to the start of the file,Currentmeans relative to the current offset, andEndmeans relative to the end.
Options for toReadableStream.
- autoClose: boolean
If the
readeris also aCloser, automatically close thereaderwhenEOFis encountered, or a read error occurs. - chunkSize: number
The size of chunks to allocate to read.
- strategy: QueuingStrategy<Uint8Array>
The queuing strategy to create the
ReadableStreamwith.
Options for toWritableStream.
- autoClose: boolean
If the
writeris also aCloser, automatically close thewriterwhen the stream is closed, aborted, or a write error occurs.
An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource asynchronously.
- write(p: Uint8Array): Promise<number>
Writes
p.byteLengthbytes frompto the underlying data stream. It resolves to the number of bytes written fromp(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 ton<p.byteLength.write()must not modify the slice data, even temporarily.
An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource synchronously.
- writeSync(p: Uint8Array): number
Writes
p.byteLengthbytes frompto the underlying data stream. It returns the number of bytes written fromp(0<=n<=p.byteLength) and any error encountered that caused the write to stop early.writeSync()must throw a non-null error if it returnsn<p.byteLength.writeSync()must not modify the slice data, even temporarily.