|
const buff = Buffer.alloc(data.length + 1); |
Current implementation assume stdin is always a binary stream, but it does not really check the type. So if pass Readable.from(string)
as stdin, most time it works, unless the string contains non-ASCII characters, in such case, data
is string and data.length
is number of UTF16 code units, which will smaller than the number of UTF8 code units or bytes.
I suggest the implementation should either deal with the string case, or just throw type error if not buffer.