summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-06-28 02:20:48 +0200
committerGitHub <noreply@github.com>2020-06-27 20:20:48 -0400
commit2da084058397efd6f517ba98c9882760ec0a7bd6 (patch)
treec64ffe84b2ad5b015921b79eec01d77af1083da6
parenta829fa8f57a2063492aab564ec1f15da21eb851c (diff)
fix(std/io): export streams.ts & added docs (#6535)
-rw-r--r--std/io/README.md34
-rw-r--r--std/io/mod.ts1
2 files changed, 35 insertions, 0 deletions
diff --git a/std/io/README.md b/std/io/README.md
index 2432a468b..ead1d1d4c 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 ca07bac43..f92feb6ef 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";