Skip to content

Commit

Permalink
feat: streams utilities (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Oct 12, 2021
1 parent 0efea9f commit b58b10c
Show file tree
Hide file tree
Showing 34 changed files with 1,038 additions and 616 deletions.
4 changes: 2 additions & 2 deletions archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```ts
import { Tar } from "https://deno.land/std@$STD_VERSION/archive/tar.ts";
import { Buffer } from "https://deno.land/std@$STD_VERSION/io/buffer.ts";
import { copy } from "https://deno.land/std@$STD_VERSION/io/streams.ts";
import { copy } from "https://deno.land/std@$STD_VERSION/streams/conversion.ts";

const tar = new Tar();
const content = new TextEncoder().encode("Deno.land");
Expand All @@ -32,7 +32,7 @@ writer.close();
import { Untar } from "https://deno.land/std@$STD_VERSION/archive/tar.ts";
import { ensureFile } from "https://deno.land/std@$STD_VERSION/fs/ensure_file.ts";
import { ensureDir } from "https://deno.land/std@$STD_VERSION/fs/ensure_dir.ts";
import { copy } from "https://deno.land/std@$STD_VERSION/io/streams.ts";
import { copy } from "https://deno.land/std@$STD_VERSION/streams/conversion.ts";

const reader = await Deno.open("./out.tar", { read: true });
const untar = new Untar(reader);
Expand Down
2 changes: 1 addition & 1 deletion archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import { MultiReader } from "../io/readers.ts";
import { Buffer, PartialReadError } from "../io/buffer.ts";
import { assert } from "../_util/assert.ts";
import { readAll } from "../io/streams.ts";
import { readAll } from "../streams/conversion.ts";

type Reader = Deno.Reader;
type Seeker = Deno.Seeker;
Expand Down
2 changes: 1 addition & 1 deletion archive/tar_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { assert, assertEquals } from "../testing/asserts.ts";
import { dirname, fromFileUrl, resolve } from "../path/mod.ts";
import { Tar, Untar } from "./tar.ts";
import { Buffer } from "../io/buffer.ts";
import { copy, readAll } from "../io/streams.ts";
import { copy, readAll } from "../streams/conversion.ts";

const moduleDir = dirname(fromFileUrl(import.meta.url));
const testdataDir = resolve(moduleDir, "testdata");
Expand Down
2 changes: 1 addition & 1 deletion encoding/binary_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
writeVarnum,
} from "./binary.ts";
import { Buffer } from "../io/buffer.ts";
import { readerFromIterable } from "../io/streams.ts";
import { readerFromIterable } from "../streams/conversion.ts";

Deno.test("testReadExactMultipleReads", async function () {
const reader = readerFromIterable([
Expand Down
2 changes: 1 addition & 1 deletion examples/cat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { copy } from "../io/streams.ts";
import { copy } from "../streams/conversion.ts";
const filenames = Deno.args;
for (const filename of filenames) {
const file = await Deno.open(filename);
Expand Down
2 changes: 1 addition & 1 deletion examples/catj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { parse } from "../flags/mod.ts";
import * as colors from "../fmt/colors.ts";
import { readAll } from "../io/streams.ts";
import { readAll } from "../streams/conversion.ts";

const decoder = new TextDecoder();

Expand Down
2 changes: 1 addition & 1 deletion examples/chat/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { fromFileUrl } from "../../path/mod.ts";
import { readableStreamFromReader } from "../../io/streams.ts";
import { readableStreamFromReader } from "../../streams/conversion.ts";

const clients = new Map<number, WebSocket>();
let clientId = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/echo_server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { copy } from "../io/streams.ts";
import { copy } from "../streams/conversion.ts";

const hostname = "0.0.0.0";
const port = 8080;
Expand Down
2 changes: 1 addition & 1 deletion http/_io.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { BufReader, BufWriter } from "../io/buffer.ts";
import { copy, iterateReader } from "../io/streams.ts";
import { copy, iterateReader } from "../streams/conversion.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { assert } from "../_util/assert.ts";
import { Response, ServerRequest } from "./server_legacy.ts";
Expand Down
2 changes: 1 addition & 1 deletion http/_io_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "./_io.ts";
import { Buffer, BufReader, ReadLineResult } from "../io/buffer.ts";
import { StringReader } from "../io/readers.ts";
import { readAll } from "../io/streams.ts";
import { readAll } from "../streams/conversion.ts";
import { mockConn } from "./_mock_conn.ts";
import { Response, ServerRequest } from "./server_legacy.ts";

Expand Down
2 changes: 1 addition & 1 deletion http/file_server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
assertStringIncludes,
} from "../testing/asserts.ts";
import { BufReader } from "../io/buffer.ts";
import { iterateReader, readAll, writeAll } from "../io/streams.ts";
import { iterateReader, readAll, writeAll } from "../streams/conversion.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { FileServerArgs } from "./file_server.ts";
import { dirname, fromFileUrl, join, resolve } from "../path/mod.ts";
Expand Down
2 changes: 1 addition & 1 deletion http/server_legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ServerRequest {
*
* ```ts
* import { ServerRequest } from "https://deno.land/std@$STD_VERSION/http/server_legacy.ts";
* import { readAll } from "https://deno.land/std@$STD_VERSION/io/streams.ts";
* import { readAll } from "https://deno.land/std@$STD_VERSION/streams/conversion.ts";
*
* const req = new ServerRequest();
* const buf = await readAll(req.body);
Expand Down
2 changes: 1 addition & 1 deletion http/server_legacy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
serveTLS,
} from "./server_legacy.ts";
import { Buffer, BufReader, BufWriter } from "../io/buffer.ts";
import { readAll, writeAll } from "../io/streams.ts";
import { readAll, writeAll } from "../streams/conversion.ts";
import { delay } from "../async/delay.ts";
import { mockConn } from "./_mock_conn.ts";
import { dirname, fromFileUrl, join, resolve } from "../path/mod.ts";
Expand Down
2 changes: 1 addition & 1 deletion http/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "./server.ts";
import { mockConn as createMockConn } from "./_mock_conn.ts";
import { dirname, fromFileUrl, join, resolve } from "../path/mod.ts";
import { readAll, writeAll } from "../io/streams.ts";
import { readAll, writeAll } from "../streams/conversion.ts";
import { deferred, delay } from "../async/mod.ts";
import {
assert,
Expand Down
40 changes: 1 addition & 39 deletions io/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ Create a `Writer` object for `string`.

```ts
import {
copy,
copyN,
StringReader,
StringWriter,
} from "https://deno.land/std@$STD_VERSION/io/mod.ts";
import { copy } from "https://deno.land/std@$STD_VERSION/streams/mod.ts";

const w = new StringWriter("base");
const r = new StringReader("0123456789");
Expand All @@ -90,41 +90,3 @@ console.log(w.toString()); // base0123456789
base0123
base0123456789
```

### readerFromStreamReader

Creates a `Reader` from a `ReadableStreamDefaultReader`.

```ts
import {
copy,
readerFromStreamReader,
} from "https://deno.land/std@$STD_VERSION/io/mod.ts";
const res = await fetch("https://deno.land");
const file = await Deno.open("./deno.land.html", { create: true, write: true });

const reader = readerFromStreamReader(res.body!.getReader());
await copy(reader, file);
file.close();
```

### writerFromStreamWriter

Creates a `Writer` from a `WritableStreamDefaultWriter`.

```ts
import {
copy,
writerFromStreamWriter,
} from "https://deno.land/std@$STD_VERSION/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 = writerFromStreamWriter(writableStream.getWriter());
await copy(file, writer);
file.close();
```
2 changes: 1 addition & 1 deletion io/buffer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "./buffer.ts";
import * as iotest from "./_iotest.ts";
import { StringReader } from "./readers.ts";
import { writeAllSync } from "./streams.ts";
import { writeAllSync } from "../streams/conversion.ts";
import { StringWriter } from "./writers.ts";

const MAX_SIZE = 2 ** 32 - 2;
Expand Down
2 changes: 1 addition & 1 deletion io/readers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assertEquals } from "../testing/asserts.ts";
import { LimitedReader, MultiReader, StringReader } from "./readers.ts";
import { StringWriter } from "./writers.ts";
import { copyN } from "./util.ts";
import { copy, readAll } from "./streams.ts";
import { copy, readAll } from "../streams/conversion.ts";

Deno.test("ioStringReader", async function () {
const r = new StringReader("abcdef");
Expand Down
Loading

0 comments on commit b58b10c

Please sign in to comment.