diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-27 13:52:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-27 13:52:27 +0200 |
commit | 6c093c0b5a1c908712c95c8657c42b30421bd519 (patch) | |
tree | 9bf7d5b903b754c71ca7fb5bb3845f609c4ca6d4 | |
parent | 6be3487f73313b8928a325c56a2f1914dada7db0 (diff) |
fix(cli): Buffer.bytes() ArrayBuffer size (#6511)
-rw-r--r-- | cli/js/buffer.ts | 2 | ||||
-rw-r--r-- | cli/tests/unit/buffer_test.ts | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index 473affe3d..6a5105908 100644 --- a/cli/js/buffer.ts +++ b/cli/js/buffer.ts @@ -40,7 +40,7 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync { } bytes(): Uint8Array { - return this.#buf.subarray(this.#off); + return this.#buf.slice(this.#off); } empty(): boolean { diff --git a/cli/tests/unit/buffer_test.ts b/cli/tests/unit/buffer_test.ts index 644f05952..dc80c9c6d 100644 --- a/cli/tests/unit/buffer_test.ts +++ b/cli/tests/unit/buffer_test.ts @@ -298,3 +298,16 @@ unitTest(function testWriteAllSync(): void { assertEquals(testBytes[i], actualBytes[i]); } }); + +unitTest(function testBufferBytesArrayBufferLength(): void { + const bytes = new TextEncoder().encode("a"); + const reader = new Deno.Buffer(); + Deno.writeAllSync(reader, bytes); + + const writer = new Deno.Buffer(); + writer.readFromSync(reader); + const actualBytes = writer.bytes(); + + assertEquals(bytes.byteLength, 1); + assertEquals(bytes.byteLength, actualBytes.buffer.byteLength); +}); |