From 4c0ac4ffcc0c02917abbd6c4235d60707c80b261 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 25 Sep 2024 14:01:56 +1000 Subject: [PATCH] BREAKING(io/unstable): remove `readStringDelim()` (#6001) --- io/deno.json | 1 - io/mod.ts | 1 - io/read_string_delim.ts | 45 ------------------------------ io/read_string_delim_test.ts | 53 ------------------------------------ 4 files changed, 100 deletions(-) delete mode 100644 io/read_string_delim.ts delete mode 100644 io/read_string_delim_test.ts diff --git a/io/deno.json b/io/deno.json index 0b470bc26..11dfbd1a6 100644 --- a/io/deno.json +++ b/io/deno.json @@ -15,7 +15,6 @@ "./read-int": "./read_int.ts", "./read-long": "./read_long.ts", "./read-short": "./read_short.ts", - "./read-string-delim": "./read_string_delim.ts", "./reader-from-stream-reader": "./reader_from_stream_reader.ts", "./string-reader": "./string_reader.ts", "./string-writer": "./string_writer.ts", diff --git a/io/mod.ts b/io/mod.ts index 2caad34e2..33152148d 100644 --- a/io/mod.ts +++ b/io/mod.ts @@ -28,7 +28,6 @@ export * from "./read_delim.ts"; export * from "./read_int.ts"; export * from "./read_long.ts"; export * from "./read_short.ts"; -export * from "./read_string_delim.ts"; export * from "./reader_from_stream_reader.ts"; export * from "./string_reader.ts"; export * from "./string_writer.ts"; diff --git a/io/read_string_delim.ts b/io/read_string_delim.ts deleted file mode 100644 index ce45fcab6..000000000 --- a/io/read_string_delim.ts +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -// This module is browser compatible. - -import type { Reader } from "./types.ts"; -import { readDelim } from "./read_delim.ts"; - -/** - * Read {@linkcode Reader} chunk by chunk, splitting based on delimiter. - * - * @example Usage - * ```ts - * import { readStringDelim } from "@std/io/read-string-delim"; - * import { assert } from "@std/assert/assert" - * - * using fileReader = await Deno.open("README.md"); - * - * for await (let line of readStringDelim(fileReader, "\n")) { - * assert(typeof line === "string"); - * } - * ``` - * - * @param reader The reader to read from - * @param delim The delimiter to split the reader by - * @param decoderOpts The options - * @returns The async iterator of strings - * - * @deprecated Pipe the readable stream through a - * {@linkcode https://jsr.io/@std/streams/doc/~/TextDelimiterStream | TextDelimiterStream} - * instead. This will be removed in 0.225.0. - */ -export async function* readStringDelim( - reader: Reader, - delim: string, - decoderOpts?: { - encoding?: string; - fatal?: boolean; - ignoreBOM?: boolean; - }, -): AsyncIterableIterator { - const encoder = new TextEncoder(); - const decoder = new TextDecoder(decoderOpts?.encoding, decoderOpts); - for await (const chunk of readDelim(reader, encoder.encode(delim))) { - yield decoder.decode(chunk); - } -} diff --git a/io/read_string_delim_test.ts b/io/read_string_delim_test.ts deleted file mode 100644 index 75fa6271a..000000000 --- a/io/read_string_delim_test.ts +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -// This code has been ported almost directly from Go's src/bytes/buffer_test.go -// Copyright 2009 The Go Authors. All rights reserved. BSD license. -// https://github.com/golang/go/blob/master/LICENSE -import { assertEquals } from "@std/assert"; -import { readStringDelim } from "./read_string_delim.ts"; -import { StringReader } from "./string_reader.ts"; - -Deno.test("[io] readStringDelim basic", async () => { - const delim = "!#$%&()=~"; - const exp = [ - "", - "a", - "bc", - "def", - "", - "!", - "!#", - "!#$%&()=", - "#$%&()=~", - "", - "", - ]; - const str = exp.join(delim); - const arr: string[] = []; - for await (const v of readStringDelim(new StringReader(str), delim)) { - arr.push(v); - } - assertEquals(arr, exp); -}); - -Deno.test("[io] readStringDelim bigger delim than buf size", async () => { - // 0123456789... - const delim = Array.from({ length: 1025 }).map((_, i) => i % 10).join(""); - const exp = ["", "a", "bc", "def", "01", "012345678", "123456789", "", ""]; - const str = exp.join(delim); - const arr: string[] = []; - for await (const v of readStringDelim(new StringReader(str), delim)) { - arr.push(v); - } - assertEquals(arr, exp); -}); - -Deno.test("[io] readStringDelim delim=1213", async () => { - const delim = "1213"; - const exp = ["", "a", "bc", "def", "01", "012345678", "123456789", "", ""]; - const str = exp.join(delim); - const arr: string[] = []; - for await (const v of readStringDelim(new StringReader(str), "1213")) { - arr.push(v); - } - assertEquals(arr, exp); -});