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

string_reader.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
41
42
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import { Buffer } from "./buffer.ts";
/** * Reader utility for strings. * * @example * ```ts * import { StringReader } from "https://deno.land/std@$STD_VERSION/io/string_reader.ts"; * * const data = new Uint8Array(6); * const r = new StringReader("abcdef"); * const res0 = await r.read(data); * const res1 = await r.read(new Uint8Array(6)); * * // Number of bytes read * console.log(res0); // 6 * console.log(res1); // null, no byte left to read. EOL * * // text * * console.log(new TextDecoder().decode(data)); // abcdef * ``` * * **Output:** * * ```text * 6 * null * abcdef * ``` * * @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 class StringReader extends Buffer { constructor(s: string) { super(new TextEncoder().encode(s).buffer); }}
std

Version Info

Tagged at
6 months ago