std/streams/writable_stream_from_writer.ts
Yusuke Tanaka 9c3c53e65b
docs(streams): improve docs for stabilization (#4852)
This commit improves docs of the streams module.

Towards #3764

---------

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2024-05-27 18:27:40 -07:00

48 lines
1.7 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import type { Writer } from "@std/io/types";
import { toWritableStream } from "@std/io/to-writable-stream";
/**
* Options for {@linkcode writableStreamFromWriter}.
*
* @deprecated This will be removed in 1.0.0. Use {@linkcode https://jsr.io/@std/io/doc/~/toWritableStream | toWritableStream} instead.
*/
export interface WritableStreamFromWriterOptions {
/**
* If the `writer` is also a `Closer`, automatically close the `writer`
* when the stream is closed, aborted, or a write error occurs.
*
* @default {true}
*/
autoClose?: boolean;
}
/**
* Create a {@linkcode WritableStream} from a {@linkcode https://jsr.io/@std/io/doc/types/~/Writer | Writer}.
*
* @param writer A `Writer` to convert into a `WritableStream`.
* @param options Options for the `writableStreamFromWriter` function.
* @returns A `WritableStream` of `Uint8Array`s.
*
* @example Convert `Deno.stdout` into a writable stream
* ```ts
* // Note that you can directly get the writer from `Deno.stdout` by
* // `Deno.stdout.writable`. This example is just for demonstration purposes;
* // definitely not a recommended way.
*
* import { writableStreamFromWriter } from "@std/streams/writable-stream-from-writer";
*
* const stdoutStream = writableStreamFromWriter(Deno.stdout);
* ```
*
* @deprecated This will be removed in 1.0.0. Use {@linkcode https://jsr.io/@std/io/doc/~/toWritableStream | toWritableStream} instead.
*/
export function writableStreamFromWriter(
writer: Writer,
options: WritableStreamFromWriterOptions = {},
): WritableStream<Uint8Array> {
return toWritableStream(writer, options);
}