From 6c093c0b5a1c908712c95c8657c42b30421bd519 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Sat, 27 Jun 2020 13:52:27 +0200 Subject: [PATCH] fix(cli): Buffer.bytes() ArrayBuffer size (#6511) --- cli/js/buffer.ts | 2 +- cli/tests/unit/buffer_test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index 473affe3dc..6a5105908e 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 644f05952f..dc80c9c6d3 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); +});