Skip to content
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

Support a non-string based EncoderStream/DecoderStream #242

Open
bpasero opened this issue Jun 17, 2020 · 2 comments
Open

Support a non-string based EncoderStream/DecoderStream #242

bpasero opened this issue Jun 17, 2020 · 2 comments

Comments

@bpasero
Copy link

bpasero commented Jun 17, 2020

Referring to:

export interface EncoderStream {
write(str: string): Buffer;
end(): Buffer | undefined;
}
export interface DecoderStream {
write(buf: Buffer): string;
end(): string | undefined;
}

I am not sure why we cannot work without strings in these methods and thus avoid having to create strings while talking to the library. Imho everything here should be Uint8Array based and not string based at all.

@bpasero
Copy link
Author

bpasero commented Jun 18, 2020

Maybe as an alternative, string | Buffer could be supported, similar to how node.js streams support both.

@ashtuchkin
Copy link
Owner

This is in line with StreamDecoder in Node.js and TextDecoder/TextEncoder in WHATWG Encodings standard. Conceptually encoding/decoding is a conversion between bytes and strings and in vast majority of cases it makes sense to expose strings to clients. In rare cases where you convert from bytes in encoding A to bytes in encoding B, we recommend just calling encode(decode()) or piping the streams.

Also, btw, Node.js streams can also work with strings just fine, using "object" mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants