From 2da084058397efd6f517ba98c9882760ec0a7bd6 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Sun, 28 Jun 2020 02:20:48 +0200 Subject: [PATCH] fix(std/io): export streams.ts & added docs (#6535) --- std/io/README.md | 34 ++++++++++++++++++++++++++++++++++ std/io/mod.ts | 1 + 2 files changed, 35 insertions(+) diff --git a/std/io/README.md b/std/io/README.md index 2432a468b0..ead1d1d4c2 100644 --- a/std/io/README.md +++ b/std/io/README.md @@ -123,3 +123,37 @@ console.log(w.toString()); // base0123456789 base0123 base0123456789 ``` + +## Streams + +### fromStreamReader + +Creates a `Reader` from a `ReadableStreamDefaultReader` + +```ts +import { fromStreamReader } from "https://deno.land/std/io/mod.ts"; +const res = await fetch("https://deno.land"); +const file = await Deno.open("./deno.land.html", { create: true, write: true }); + +const reader = fromStreamReader(res.body!.getReader()); +await Deno.copy(reader, file); +file.close(); +``` + +### fromStreamWriter + +Creates a `Writer` from a `WritableStreamDefaultWriter` + +```ts +import { fromStreamWriter } from "https://deno.land/std/io/mod.ts"; +const file = await Deno.open("./deno.land.html", { read: true }); + +const writableStream = new WritableStream({ + write(chunk): void { + console.log(chunk); + }, +}); +const writer = fromStreamWriter(writableStream.getWriter()); +await Deno.copy(file, writer); +file.close(); +``` diff --git a/std/io/mod.ts b/std/io/mod.ts index ca07bac437..f92feb6ef3 100644 --- a/std/io/mod.ts +++ b/std/io/mod.ts @@ -2,3 +2,4 @@ export * from "./bufio.ts"; export * from "./ioutil.ts"; export * from "./readers.ts"; export * from "./writers.ts"; +export * from "./streams.ts";