Skip to main content
Deno 2 is finally here 🎉️
Learn more
Extremely Popular
Go to Latest
function streams.writeAllSync
import { streams } from "https://deno.land/x/postgres@v0.17.0/tests/test_deps.ts";
const { writeAllSync } = streams;

Synchronously write all the content of the array buffer (arr) to the writer (w).

import { Buffer } from "https://deno.land/std@0.224.0/io/buffer.ts";
import { writeAllSync } from "https://deno.land/std@0.224.0/streams/conversion.ts";

// Example writing to stdout
let contentBytes = new TextEncoder().encode("Hello World");
writeAllSync(Deno.stdout, contentBytes);

// Example writing to file
contentBytes = new TextEncoder().encode("Hello World");
const file = Deno.openSync('test.file', {write: true});
writeAllSync(file, contentBytes);
file.close();

// Example writing to buffer
contentBytes = new TextEncoder().encode("Hello World");
const writer = new Buffer();
writeAllSync(writer, contentBytes);
console.log(writer.bytes().length);  // 11

Parameters

w: Deno.WriterSync
arr: Uint8Array