MCPcopy Create free account
hub / github.com/denoland/std / readSync

Method readSync

io/buffer.ts:244–257  ·  view source on GitHub ↗

* Reads the next `p.length` bytes 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`). * * @example Usage * ```ts * import { Buffer } from "@std/io/buffer"; * import { assertEquals

(p: Uint8Array)

Source from the content-addressed store, hash-verified

242 * @returns The number of bytes read.
243 */
244 readSync(p: Uint8Array): number | null {
245 if (this.empty()) {
246 // Buffer is empty, reset to recover space.
247 this.reset();
248 if (p.byteLength === 0) {
249 // this edge case is tested in 'bufferReadEmptyAtEOF' test
250 return 0;
251 }
252 return null;
253 }
254 const nread = copy(this.#buf.subarray(this.#off), p);
255 this.#off += nread;
256 return nread;
257 }
258
259 /**
260 * Reads the next `p.length` bytes from the buffer or until the buffer is

Callers 1

readMethod · 0.95

Calls 3

emptyMethod · 0.95
resetMethod · 0.95
copyFunction · 0.90

Tested by

no test coverage detected