1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix(cli): Buffer.bytes() ArrayBuffer size (#6511)

This commit is contained in:
Marcos Casagrande 2020-06-27 13:52:27 +02:00 committed by GitHub
parent 6be3487f73
commit 6c093c0b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -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 {

View file

@ -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);
});