Classes
A variable-sized buffer of bytes with read() and write() methods.
- bytes(options?): 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(): voidNo documentation available
- 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>
NOTE: This methods writes bytes synchronously; it's provided for compatibility with
Writerinterface. - writeSync(p: Uint8Array): numberNo documentation available
- name: stringNo documentation available
- buffered(): numberNo documentation available
- create(): BufReaderr: Reader,size?: number
return new BufReader unless r is BufReader
- peek(n: number): Promise<Uint8Array | null>
peek()returns the nextnbytes without advancing the reader. The bytes stop being valid at the next read call. - read(p: Uint8Array): Promise<number | null>
reads data into p. It returns the number of bytes read into p. The bytes are taken from at most one Read on the underlying Reader, hence n may be less than len(p). To read exactly len(p) bytes, use io.ReadFull(b, p).
- readByte(): Promise<number | null>
Returns the next byte [0, 255] or
null. - readFull(p: Uint8Array): Promise<Uint8Array | null>
reads exactly
p.lengthbytes intop. - readLine(): Promise<ReadLineResult | null>
readLine()is a low-level line-reading primitive. Most callers should usereadString('\n')instead or use a Scanner. - readSlice(delim: number): Promise<Uint8Array | null>
readSlice()reads until the first occurrence ofdelimin the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read. - readString(delim: string): Promise<string | null>
readString() reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often
null). ReadString returns err !== null if and only if the returned data does not end in delim. For simple uses, a Scanner may be more convenient. - reset(r: Reader): void
Discards any buffered data, resets all state, and switches the buffered reader to read from r.
- size(): number
Returns the size of the underlying buffer in bytes.
BufWriter implements buffering for an deno.Writer object. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes, and flush(), will return the error. After all data has been written, the client should call the flush() method to guarantee all data has been forwarded to the underlying deno.Writer.
- create(): BufWriterwriter: Writer,size?: number
return new BufWriter unless writer is BufWriter
- flush(): Promise<void>
Flush writes any buffered data to the underlying io.Writer.
- reset(w: Writer): void
Discards any unflushed buffered data, clears any error, and resets buffer to write its output to w.
- write(data: Uint8Array): Promise<number>
Writes the contents of
datainto the buffer. If the contents won't fully fit into the buffer, those bytes that are copied into the buffer will be flushed to the writer and the remaining bytes are then copied into the now empty buffer.
BufWriterSync implements buffering for a deno.WriterSync object. If an error occurs writing to a WriterSync, no more data will be accepted and all subsequent writes, and flush(), will return the error. After all data has been written, the client should call the flush() method to guarantee all data has been forwarded to the underlying deno.WriterSync.
- create(): BufWriterSyncwriter: WriterSync,size?: number
return new BufWriterSync unless writer is BufWriterSync
- flush(): void
Flush writes any buffered data to the underlying io.WriterSync.
- reset(w: WriterSync): void
Discards any unflushed buffered data, clears any error, and resets buffer to write its output to w.
- writeSync(data: Uint8Array): number
Writes the contents of
datainto the buffer. If the contents won't fully fit into the buffer, those bytes that can are copied into the buffer, the buffer is the flushed to the writer and the remaining bytes are copied into the now empty buffer.
- read(p: Uint8Array): Promise<number | null>No documentation available
Reader utility for combining multiple readers
- read(p: Uint8Array): Promise<number | null>No documentation available
Reader utility for strings.
Writer utility for buffering string chunks.
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.
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 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).
Copy N size at the most. If read size is lesser than N, then returns nread
Read delimited bytes from a Reader.
Read big endian 32bit integer from BufReader
Read strings line-by-line from a Reader.
Read big endian 64bit long from BufReader
Read a range of bytes from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.
Read a range of bytes synchronously from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.
Read big endian 16bit short from BufReader
Read Reader chunk by chunk, splitting based on delimiter.
Slice number into 64bit big endian byte array
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.
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, the default is ~16KiB, which is the maximum size that Deno operations can currently support.
- 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.
Result type returned by of BufReader.readLine().