diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-04-21 02:22:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-21 02:22:55 +0200 |
commit | 03019e778189b38938f1238f22652162de5a7434 (patch) | |
tree | cf16b44be07c1c488ffe4f31fe77eab7f6bd8c95 /ext/net/01_net.js | |
parent | aaaa877d91c5f8b88722fd1ec725791b0eb4efe0 (diff) |
Revert various PRs related to "ext/http" (#14339)
* Revert "feat(ext/http): stream auto resp body compression (#14325)"
* Revert "core: introduce `resource.read_return` (#14331)"
* Revert "perf(http): optimize `ReadableStream`s backed by a resource (#14284)"
Diffstat (limited to 'ext/net/01_net.js')
-rw-r--r-- | ext/net/01_net.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/ext/net/01_net.js b/ext/net/01_net.js index fde75fe56..48cbfaaab 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -4,7 +4,7 @@ ((window) => { const core = window.Deno.core; const { BadResourcePrototype, InterruptedPrototype } = core; - const { WritableStream, readableStreamForRid } = window.__bootstrap.streams; + const { ReadableStream, WritableStream } = window.__bootstrap.streams; const { Error, ObjectPrototypeIsPrototypeOf, @@ -65,6 +65,8 @@ return core.opAsync("op_dns_resolve", { query, recordType, options }); } + const DEFAULT_CHUNK_SIZE = 64 * 1024; + function tryClose(rid) { try { core.close(rid); @@ -73,6 +75,32 @@ } } + function readableStreamForRid(rid) { + return new ReadableStream({ + type: "bytes", + async pull(controller) { + const v = controller.byobRequest.view; + try { + const bytesRead = await read(rid, v); + if (bytesRead === null) { + tryClose(rid); + controller.close(); + controller.byobRequest.respond(0); + } else { + controller.byobRequest.respond(bytesRead); + } + } catch (e) { + controller.error(e); + tryClose(rid); + } + }, + cancel() { + tryClose(rid); + }, + autoAllocateChunkSize: DEFAULT_CHUNK_SIZE, + }); + } + function writableStreamForRid(rid) { return new WritableStream({ async write(chunk, controller) { |