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

Method truncate

io/buffer.ts:175–184  ·  view source on GitHub ↗

* Discards all but the first `n` unread bytes from the buffer but * continues to use the same allocated storage. It throws if `n` is * negative or greater than the length of the buffer. * * @example Usage * ```ts * import { Buffer } from "@std/io/buffer"; * import { assertEquals

(n: number)

Source from the content-addressed store, hash-verified

173 * @param n The number of bytes to keep.
174 */
175 truncate(n: number) {
176 if (n === 0) {
177 this.reset();
178 return;
179 }
180 if (n < 0 || n > this.length) {
181 throw new Error("Buffer truncation out of range");
182 }
183 this.#reslice(this.#off + n);
184 }
185
186 /**
187 * Resets the contents

Callers

nothing calls this directly

Calls 2

resetMethod · 0.95
#resliceMethod · 0.95

Tested by

no test coverage detected