deno.land / std@0.224.0 / io / read_string_delim.ts

read_string_delim.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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 Reader chunk by chunk, splitting based on delimiter. * * @example * ```ts * import { readStringDelim } from "https://deno.land/std@$STD_VERSION/io/read_string_delim.ts"; * import * as path from "https://deno.land/std@$STD_VERSION/path/mod.ts"; * * const filename = path.join(Deno.cwd(), "std/io/README.md"); * let fileReader = await Deno.open(filename); * * for await (let line of readStringDelim(fileReader, "\n")) { * console.log(line); * } * ``` * * @deprecated This will be removed in 1.0.0. Use the {@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API | Web Streams API} instead. */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); }}
std

Version Info

Tagged at
6 months ago