BREAKING(io/unstable): remove readStringDelim() (#6001)

This commit is contained in:
Asher Gomez 2024-09-25 14:01:56 +10:00 committed by GitHub
parent 3500797dcb
commit 4c0ac4ffcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 0 additions and 100 deletions

View File

@ -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",

View File

@ -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";

View File

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

View File

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