Skip to content

Commit

Permalink
fix(std/io): export streams.ts & added docs (denoland#6535)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosc90 committed Jun 28, 2020
1 parent a829fa8 commit 2da0840
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions std/io/README.md
Expand Up @@ -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();
```
1 change: 1 addition & 0 deletions std/io/mod.ts
Expand Up @@ -2,3 +2,4 @@ export * from "./bufio.ts";
export * from "./ioutil.ts";
export * from "./readers.ts";
export * from "./writers.ts";
export * from "./streams.ts";

0 comments on commit 2da0840

Please sign in to comment.