1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-18 11:53:59 -05:00

fetch: make body async iterable (#2563)

This commit is contained in:
Yoshiya Hinosawa 2019-06-22 23:22:27 +09:00 committed by Ryan Dahl
parent 201ddd29a7
commit 988bcbb884
2 changed files with 15 additions and 0 deletions

View file

@ -237,6 +237,10 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
tee(): [domTypes.ReadableStream, domTypes.ReadableStream] { tee(): [domTypes.ReadableStream, domTypes.ReadableStream] {
return notImplemented(); return notImplemented();
} }
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array> {
return io.toAsyncIterator(this);
}
} }
export class Response implements domTypes.Response { export class Response implements domTypes.Response {

View file

@ -33,6 +33,17 @@ testPerm({ net: true }, async function fetchBlob(): Promise<void> {
assertEquals(blob.size, Number(headers.get("Content-Length"))); assertEquals(blob.size, Number(headers.get("Content-Length")));
}); });
testPerm({ net: true }, async function fetchAsyncIterator(): Promise<void> {
const response = await fetch("http://localhost:4545/package.json");
const headers = response.headers;
let total = 0;
for await (const chunk of response.body) {
total += chunk.length;
}
assertEquals(total, Number(headers.get("Content-Length")));
});
testPerm({ net: true }, async function responseClone(): Promise<void> { testPerm({ net: true }, async function responseClone(): Promise<void> {
const response = await fetch("http://localhost:4545/package.json"); const response = await fetch("http://localhost:4545/package.json");
const response1 = response.clone(); const response1 = response.clone();