Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/streams/mod.ts>readAllSync

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function readAllSync
import { readAllSync } from "https://deno.land/std@0.199.0/streams/mod.ts";

Synchronously reads Reader r until EOF (null) and returns the content as Uint8Array.

import { Buffer } from "https://deno.land/std@0.199.0/io/buffer.ts";
import { readAllSync } from "https://deno.land/std@0.199.0/streams/read_all.ts";

// Example from stdin
const stdinContent = readAllSync(Deno.stdin);

// Example from file
const file = Deno.openSync("my_file.txt", {read: true});
const myFileContent = readAllSync(file);
file.close();

// Example from buffer
const myData = new Uint8Array(100);
// ... fill myData array with data
const reader = new Buffer(myData.buffer);
const bufferContent = readAllSync(reader);

Returns

Uint8Array