// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. export function fromStreamWriter( streamWriter: WritableStreamDefaultWriter ): Deno.Writer { return { async write(p: Uint8Array): Promise { await streamWriter.ready; await streamWriter.write(p); return p.length; }, }; } export function fromStreamReader( streamReader: ReadableStreamDefaultReader ): Deno.Reader { const buffer = new Deno.Buffer(); return { async read(p: Uint8Array): Promise { if (buffer.empty()) { const res = await streamReader.read(); if (res.done) { return null; // EOF } await Deno.writeAll(buffer, res.value); } return buffer.read(p); }, }; }