deno.land / std@0.224.0 / streams / writer_from_stream_writer.ts

writer_from_stream_writer.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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import type { Writer } from "../io/types.ts";
/** * Create a {@linkcode Writer} from a {@linkcode WritableStreamDefaultWriter}. * * @example * ```ts * import { copy } from "https://deno.land/std@$STD_VERSION/io/copy.ts"; * import { writerFromStreamWriter } from "https://deno.land/std@$STD_VERSION/streams/writer_from_stream_writer.ts"; * * using file = await Deno.open("./deno.land.html", { read: true }); * * const writableStream = new WritableStream({ * write(chunk): void { * console.log(chunk); * }, * }); * const writer = writerFromStreamWriter(writableStream.getWriter()); * await copy(file, writer); * ``` * * @deprecated This will be removed in 1.0.0. Use {@linkcode WritableStreamDefaultWriter} directly. */export function writerFromStreamWriter( streamWriter: WritableStreamDefaultWriter<Uint8Array>,): Writer { return { async write(p: Uint8Array): Promise<number> { await streamWriter.ready; await streamWriter.write(p); return p.length; }, };}
std

Version Info

Tagged at
6 months ago