0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 20:25:12 -05:00

fix(std/io): export streams.ts & added docs (#6535)

This commit is contained in:
Marcos Casagrande 2020-06-28 02:20:48 +02:00 committed by GitHub
parent a829fa8f57
commit 2da0840583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -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();
```

View file

@ -2,3 +2,4 @@ export * from "./bufio.ts";
export * from "./ioutil.ts";
export * from "./readers.ts";
export * from "./writers.ts";
export * from "./streams.ts";