From d308e8d0c0469419517e05a36ba070633168dc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 29 Apr 2020 22:38:10 +0200 Subject: BREAKING: remove custom implementation of Deno.Buffer.toString() (#4992) Keep in mind Buffer.toString() still exists, but returns [object Object]. Reason for removal of Buffer.toString() was that it implicitly used TextDecoder with fixed "utf-8" encoding and no way to customize the encoding. --- cli/js/buffer.ts | 6 ------ cli/js/lib.deno.ns.d.ts | 14 +++++++------- cli/js/tests/buffer_test.ts | 1 - 3 files changed, 7 insertions(+), 14 deletions(-) (limited to 'cli/js') diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index fdacf70a9..dbe7606fd 100644 --- a/cli/js/buffer.ts +++ b/cli/js/buffer.ts @@ -6,7 +6,6 @@ import { Reader, Writer, ReaderSync, WriterSync } from "./io.ts"; import { assert } from "./util.ts"; -import { TextDecoder } from "./web/text_encoding.ts"; // MIN_READ is the minimum ArrayBuffer size passed to a read call by // buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond @@ -44,11 +43,6 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync { return this.#buf.subarray(this.#off); } - toString(): string { - const decoder = new TextDecoder(); - return decoder.decode(this.#buf.subarray(this.#off)); - } - empty(): boolean { return this.#buf.byteLength <= this.#off; } diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index d7d885b5b..aca0fc114 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -847,12 +847,6 @@ declare namespace Deno { * least until the next buffer modification, so immediate changes to the * slice will affect the result of future reads. */ bytes(): Uint8Array; - /** Returns the contents of the unread portion of the buffer as a `string`. - * - * **Warning**: if multibyte characters are present when data is flowing - * through the buffer, this method may result in incorrect strings due to a - * character being split. */ - toString(): string; /** 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. */ @@ -873,9 +867,15 @@ declare namespace Deno { readSync(p: Uint8Array): number | null; /** Reads the next `p.length` bytes from the buffer or until the buffer is * drained. Resolves to the number of bytes read. If the buffer has no - * data to return, resolves to EOF (`null`). */ + * data to return, resolves to EOF (`null`). + * + * NOTE: This methods reads bytes sychronously; it's provided for + * compatibility with `Reader` interfaces. + */ read(p: Uint8Array): Promise; writeSync(p: Uint8Array): number; + /** NOTE: This methods writes bytes sychronously; it's provided for + * compatibility with `Writer` interface. */ write(p: Uint8Array): Promise; /** Grows the buffer's capacity, if necessary, to guarantee space for * another `n` bytes. After `.grow(n)`, at least `n` bytes can be written to diff --git a/cli/js/tests/buffer_test.ts b/cli/js/tests/buffer_test.ts index e45bcb976..ac2d7db7b 100644 --- a/cli/js/tests/buffer_test.ts +++ b/cli/js/tests/buffer_test.ts @@ -35,7 +35,6 @@ function check(buf: Deno.Buffer, s: string): void { const decoder = new TextDecoder(); const bytesStr = decoder.decode(bytes); assertEquals(bytesStr, s); - assertEquals(buf.length, buf.toString().length); assertEquals(buf.length, s.length); } -- cgit v1.2.3