mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(cli): Buffer.bytes() ArrayBuffer size (#6511)
This commit is contained in:
parent
6be3487f73
commit
6c093c0b5a
2 changed files with 14 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue