UNPKG

@denodnt/logger

Version:

deno logger available for deno and NPM

55 lines (53 loc) 1.66 kB
"use strict"; // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. Object.defineProperty(exports, "__esModule", { value: true }); exports.writeAllSync = exports.writeAll = void 0; /** * Write all the content of the array buffer (`arr`) to the writer (`w`). * * @example * ```ts * import { writeAll } from "@std/io/write-all"; * // Example writing to stdout * let contentBytes = new TextEncoder().encode("Hello World"); * await writeAll(Deno.stdout, contentBytes); * * // Example writing to file * contentBytes = new TextEncoder().encode("Hello World"); * using file = await Deno.open('test.file', {write: true}); * await writeAll(file, contentBytes); * ``` */ async function writeAll(writer, data) { let nwritten = 0; while (nwritten < data.length) { nwritten += await writer.write(data.subarray(nwritten)); } } exports.writeAll = writeAll; /** * Synchronously write all the content of the array buffer (`arr`) to the * writer (`w`). * * @example * ```ts * import { writeAllSync } from "@std/io/write-all"; * * // 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"); * using file = Deno.openSync('test.file', {write: true}); * writeAllSync(file, contentBytes); * ``` */ function writeAllSync(writer, data) { let nwritten = 0; while (nwritten < data.length) { nwritten += writer.writeSync(data.subarray(nwritten)); } } exports.writeAllSync = writeAllSync;