New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response.[method] required ArrayBuffer
or ArrayBufferView.
#43838
Comments
(async function test() {
let index = 0;
let text = '';
const cof = 1000;
const length = 1_000_000;
let readableStream;
// eslint-disable-next-line no-implicit-coercion
if (!isNaN(+length)) {
while (text.length < length) {
text += Math.random().toString(36).slice(-5);
}
readableStream = new ReadableStream<string>({
start(controller) {
(function push() {
const currentText = text.slice(index * cof, (index + 1) * cof);
if (!currentText) {
controller.close();
return;
}
index++;
controller.enqueue(currentText);
push();
})();
},
});
}
// Success in 18.5.0, but fail in 18.6.0
const data = await new Response(readableStream).text();
expect(text).toBe(data);
})(); |
This is actually expected behavior, see https://streams.spec.whatwg.org/#read-loop: "If chunk is not a Uint8Array object, reject promise with a TypeError and abort these steps." |
oh, I got it. So why it run success in |
A bug that just so happened to be handled by the PR mentioned above. You can see that browsers don't support this behavior either with a smaller repo: var readableStream = new ReadableStream({
start (controller) {
controller.enqueue('Non-uint8array')
controller.close()
}
})
new Response(readableStream).text().then(console.log) |
got. thanks |
Version
18.6.0
Platform
Darwin MacBook-Pro.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
new Response(ReadableStream<string>).text()
new Response(ReadableStream<string>).text()
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
Success in node 18.6.0
What do you see instead?
TypeError: The "input" argument must be an instance of ArrayBuffer or ArrayBufferView. Received type string ('wauy2vqxwr9mbnpg5o8ln3tw...)
Additional information
No response
The text was updated successfully, but these errors were encountered: