Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

std/io/mod.ts>StringReader

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class StringReader
extends Buffer
import { StringReader } from "https://deno.land/std@0.177.1/io/mod.ts";

Reader utility for strings.

Examples

Example 1

import { StringReader } from "https://deno.land/std@0.177.1/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:

6
null
abcdef

Constructors

new
StringReader(s: string)