-
Notifications
You must be signed in to change notification settings - Fork 285
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
Time to upgrade to modern syntax and become ESM only? #273
Comments
HI,bro,
|
just though of something else. What if instead of using
// function * decodeIterableSync(iterable) { yield transformation(...) }
// async function * decodeIterable(iterable) { yield transformation(...) }
// returns a new iterable (generator)
const iterableTransformer = iconv.decodeIterableSync(iterable)
for (let str of iterableTransformer) result += str
str = [...iconv.decodeIterableSync(iterable)].join('')
// returns a new async iterable (async generator)
const iterableTransformer = iconv.decodeIterable(fs.createReadStream('./file.txt'))
for await (let str of iterableTransformer) result += str
stream.Readable.from(iterableTransformer).pipeTo(dest) think this would be best for cross compatibility |
hi,i upgraded it ro es6 @ashtuchkin |
Hey first of all thanks for the feature requests. Let me address them one by one.
|
yea, but that requires compilers and you can't use a CDN, it needs lots of extra works for tiny projects, ESM is the feature whether or not you like it... it is the feature of how to load everything in Deno, browser and with node's now new HTTP loader ES Modules can still be loaded from cjs if you need it to be. But the tradeof is that it needs to be loaded using async with |
I read some documents, // From Buffer to ArrayBuffer:
var buf = Buffer.from("hello world!")
// var toUint = buf.buffer
// Slice (copy) its segment of the underlying ArrayBuffer
let ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
// From ArrayBuffer to Buffer:
var buffer = Buffer.from( new Uint8Array(ab) ); But the UInt8Array is enough. |
Node's Buffer is currently a subclass of UInt8Array, so we can use Buffer
in all places that accept UInt8Array (liskov substitution principle). Even
more, iconv-lite also does the reverse - it accepts UInt8Array in the same
places where it accepts Buffer, e.g. in the decode() function. The problem
is .encode() function. It currently returns Buffer, which has a richer API
than just UInt8Array and any code that depends on this will break if we
start returning UInt8Array instead. That is a breaking change of our core
API, which would require a major version bump. That will also force us to
stop supporting older Node versions where Buffer was not a subclass of
UInt8Array (before v3.0 afaik).
…On Fri, Sep 10, 2021 at 11:09 PM yosion-p ***@***.***> wrote:
I read some documents,
I think I understand the reason for using Buffer in iconv-lite,that Buffer
instances can be converted to and from normal JavaScript strings.
But Buffer seems to work only in NodeJS,and the Uint8Array's Browser
compatibility is much better.
Although they can be interchangeable, like this:
// From Buffer to ArrayBuffer:
var buf = Buffer.from("hello world!")
// var toUint = buf.buffer
// Slice (copy) its segment of the underlying ArrayBuffer
let ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
// From ArrayBuffer to Buffer:
var buffer = Buffer.from( new Uint8Array(ab) );
But the UInt8Array is enough.
I think the UInt8Array should be used like this:
get the unicode code for each word, and then fill the Uin8Array in
according to the UTF-8 encoding....
uh...🤣I created a demo <https://github.com/yosion-p/unint8array-demo>,I'm
not sure we can do that,
Maybe you can take a look at it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#273 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEZKHKL6UOCKKFNUCB3DRDUBLB7TANCNFSM5B3TCWNA>
.
|
Yes, According to official docs:
So, I don't think we need to be compatible with anything prior to Node3.0 in the future. |
We are currently compatible with v0.10+, but if we change to using
UInt8Array then we'll have to up it.
…On Sat, Sep 11, 2021, 05:44 yosion-p ***@***.***> wrote:
before v3.0 afaik
Yes, According to official docs:
v3.0 The Buffers class now inherits from Uint8Array.
<https://nodejs.org/docs/latest-v15.x/api/buffer.html#buffer_buffers_and_typedarrays>
So, are we no longer compatible with node3.0 pre-release?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#273 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEZKHOBBANY6EHTZF3RQ2LUBMQGRANCNFSM5B3TCWNA>
.
|
ppl are starting to use import instead it's more cross compatible for both browsers, Deno and Node's new experimental http import so you won't depend on npm
lots of folks want stuff to be more cross compatible between different environment. That means using import and ditching Buffer for simple Uint8Array instead.
Also how about switching to using TextDecoder instead? - it's available in Deno, browser and node globally
The text was updated successfully, but these errors were encountered: