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 typed arrays in iconv.decode #179

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Support typed arrays in iconv.decode #179

wants to merge 5 commits into from

Conversation

LMLB
Copy link
Contributor

@LMLB LMLB commented Apr 7, 2018

This simplifies using browserified iconv-lite as a standalone library in environments without Buffer by also allowing callers to provide a typed array instead of a buffer.

Note that you can't directly access the Buffer shim from outside the iconv-lite browserify bundle by default. Right now (without this change) you would either have to build and load the Buffer shim separately, indirectly access the Buffer shim via the "constructor" property of a buffer object returned from iconv.encode, or make a custom bundle that exports both iconv and Buffer.

This simplifies using browserified iconv-lite as a standalone library in environments without Buffer by also allowing callers to provide a typed array instead of a buffer.

Note that you can't directly access the Buffer shim from outside the iconv-lite browserify bundle by default. Right now (without this change) you would either have to build and load the Buffer shim separately, indirectly access the Buffer shim via the "constructor" property of a buffer object returned from iconv.encode, or make a custom bundle that exports both iconv and Buffer.
@ashtuchkin
Copy link
Owner

I see the problem, yes. On the other hand I can see how this can lead to unexpected behavior like this:

> const buf = iconv.encode("hey", "latin1");
> const arr = Uint32Array.from(buf);
> console.log(iconv.decode(arr, "latin1"));
'h\u0000\u0000\u0000e\u0000\u0000\u0000y\u0000\u0000\u0000'

Does it make sense to just reexport Buffer class and make the caller be responsible for transforming typed arrays?

@LMLB
Copy link
Contributor Author

LMLB commented Apr 8, 2018

I have limited it to only accept 8-bit typed arrays, how is that?

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

Successfully merging this pull request may close these issues.

2 participants