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
TextDecoderStream: empty Uint8Array should result in an empty string #283
Comments
I think this is intentional. Readable byte streams also don't allow enqueuing empty chunks, and it's likely that we'll want to make const rs = new ReadableStream({
type: "bytes",
start(controller) {
controller.enqueue(new Uint8Array(0)); // throws
}
}); We also don't want to enqueue empty strings if we're in the middle of a multi-byte character: const { readable, writable } = new TextDecoderStream("utf-8");
const reader = readable.getReader();
const writer = writable.getWriter();
const readPromise = reader.read();
writer.write(new Uint8Array([0xF0, 0x9F, 0x99]));
// readPromise is still pending
writer.write(new Uint8Array([0x82]))
const { done, value } = await readPromise;
// -> value == "🙂" I'm a bit surprised by Deno's That means that new TextDecoder("utf-16").decode(new Uint8Array([0x41, 0x00, 0x0A, 0x00, 0x42, 0x00]));
// -> "A\nB" I would expect you first run these chunks through a const readable = new ReadableStream({
start(controller) {
controller.enqueue(new Uint8Array([0x41, 0x00, 0x0A, 0x00, 0x42, 0x00]));
controller.close();
}
});
readable
.pipeThrough(new TextDecoderStream("utf-16"))
.pipeThrough(new LineStream());
// -> stream with chunks "A" and "B" Instead, with Deno's current readable
.pipeThrough(new LineStream())
.pipeThrough(new TextDecoderStream("utf-16"));
// -> stream with chunks "A", "䈀" and "�" |
I agree with the byte stream, that definitively would be great. I didn't take that concept into consideration when opening this issue, and as such I guess this issue is redundant. |
Closing as nothing is wrong with the spec, but rather a badly implemented utility. |
Currently the specification states:
Lets say I have a Uint8Array based transform stream that splits by line, and we have an empty line (which means the transformstream will queue an empty Uint8Array), TextDecoderStream will make that empty line disappear into thin air, which is not great.
This argument also goes for TextEncoderStream discarding an empty Uint8Array.
The text was updated successfully, but these errors were encountered: