diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-07-13 06:58:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-13 00:58:59 -0400 |
commit | 1a96a96e101140a2c39114710f93ab21c98fca01 (patch) | |
tree | fe2166564dfad2c34dbbaec2cd72b51446b1d26f /cli/js | |
parent | 63edeb1c36bfcea278c248e8be92f7dbb75f7671 (diff) |
feat(cli): add copy argument to Buffer.bytes (#6697)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/buffer.ts | 3 | ||||
-rw-r--r-- | cli/js/lib.deno.ns.d.ts | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index 3308a9a0c..4f88ff625 100644 --- a/cli/js/buffer.ts +++ b/cli/js/buffer.ts @@ -39,7 +39,8 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync { this.#buf = new Uint8Array(ab); } - bytes(): Uint8Array { + bytes(options: { copy?: boolean } = { copy: true }): Uint8Array { + if (options.copy === false) return this.#buf.subarray(this.#off); return this.#buf.slice(this.#off); } diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 32b9bb39b..373f3be2f 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -820,10 +820,12 @@ declare namespace Deno { * * The slice is valid for use only until the next buffer modification (that * is, only until the next call to a method like `read()`, `write()`, - * `reset()`, or `truncate()`). The slice aliases the buffer content at + * `reset()`, or `truncate()`). If `options.copy` is false the slice aliases the buffer content at * least until the next buffer modification, so immediate changes to the - * slice will affect the result of future reads. */ - bytes(): Uint8Array; + * slice will affect the result of future reads. + * @param options Defaults to `{ copy: true }` + */ + bytes(options?: { copy?: boolean }): Uint8Array; /** Returns whether the unread portion of the buffer is empty. */ empty(): boolean; /** A read only number of bytes of the unread portion of the buffer. */ |