Use a test stream
Example taken from https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests
This commit is contained in:
parent
8cdb31783b
commit
a74d904989
|
@ -995,6 +995,19 @@ class ExportService {
|
||||||
);
|
);
|
||||||
// TODO(MR): Productionalize
|
// TODO(MR): Productionalize
|
||||||
if (isDevBuild) {
|
if (isDevBuild) {
|
||||||
|
const testStream = new ReadableStream({
|
||||||
|
async start(controller) {
|
||||||
|
await sleep(1000);
|
||||||
|
controller.enqueue("This ");
|
||||||
|
await sleep(1000);
|
||||||
|
controller.enqueue("is ");
|
||||||
|
await sleep(1000);
|
||||||
|
controller.enqueue("a ");
|
||||||
|
await sleep(1000);
|
||||||
|
controller.enqueue("test");
|
||||||
|
controller.close();
|
||||||
|
},
|
||||||
|
}).pipeThrough(new TextEncoderStream());
|
||||||
console.log({ a: "will send req", updatedFileStream });
|
console.log({ a: "will send req", updatedFileStream });
|
||||||
// The duplex parameter needs to be set to 'half' when
|
// The duplex parameter needs to be set to 'half' when
|
||||||
// streaming requests.
|
// streaming requests.
|
||||||
|
@ -1011,9 +1024,10 @@ class ExportService {
|
||||||
// include the "duplex" parameter, so we need to cast to
|
// include the "duplex" parameter, so we need to cast to
|
||||||
// get TypeScript to let this code through. e.g. see
|
// get TypeScript to let this code through. e.g. see
|
||||||
// https://github.com/node-fetch/node-fetch/issues/1769
|
// https://github.com/node-fetch/node-fetch/issues/1769
|
||||||
const req = new Request("stream://foo", {
|
const req = new Request("stream://write/tmp/foo.txt", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: updatedFileStream,
|
// body: updatedFileStream,
|
||||||
|
body: testStream,
|
||||||
duplex: "half",
|
duplex: "half",
|
||||||
} as unknown as RequestInit);
|
} as unknown as RequestInit);
|
||||||
const res = await fetch(req);
|
const res = await fetch(req);
|
||||||
|
|
Loading…
Reference in a new issue