MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / readData

Function readData

examples/io/streams/examples/fetch/main.js:18–38  ·  view source on GitHub ↗
(url, info)

Source from the content-addressed store, hash-verified

16import { URLSearchParams } from "url";
17
18async function readData(url, info) {
19 try {
20 const response = await fetch(url, info);
21 const transformedBody = response.body.pipeThrough(new TextDecoderStream());
22
23 const reader = transformedBody.getReader();
24 while (true) {
25 const { done, value } = await reader.read();
26 if (value) {
27 trace(value);
28 }
29 if (done) {
30 trace("\n");
31 return;
32 }
33 }
34 }
35 catch(e) {
36 trace(`${e}\n`);
37 }
38}
39let controller = new AbortController();
40readData("http://httpbin.org/encoding/utf8", { signal: controller.signal });
41

Callers 1

main.jsFile · 0.85

Calls 4

fetchFunction · 0.90
pipeThroughMethod · 0.80
getReaderMethod · 0.80
readMethod · 0.65

Tested by

no test coverage detected