mafintosh / streamx

An iteration of the Node.js core streams with a series of improvements.
MIT License
226 stars 16 forks source link

fix: use w3c decoder #90

Closed ThaUnknown closed 4 months ago

ThaUnknown commented 4 months ago

uses W3C text decoder which is built in to most JS environments such as node.js, web, bun etc

reduces dependency size by some 20-ish KB

ThaUnknown commented 4 months ago

@mafintosh

ThaUnknown commented 4 months ago

b4a seems like a Buffer polyfill, I made uint8-util which roughly does the same, just with a different API so it's a lot smaller, webtorrent has been using it for quite a while now globally, pretty much since v2 it dropped buffer support :)

mafintosh commented 4 months ago

Thanks taking a look tmw. We use b4a everywhere so pretty happy with that

ThaUnknown commented 4 months ago

;-;

mafintosh commented 4 months ago

Where are you getting 20 kb from? text-decoder is <4kb

mafintosh commented 4 months ago

This needs a fallback to envs where TextDecoder doesnt exist, but honestly saving 4kb but adding the code that also supports the fallback doesn't seem worth the complexity to me

mafintosh commented 4 months ago

Ah let me re-review, i got confused by the comment, b4a is pulled in by textdecoder

mafintosh commented 4 months ago

Moved here https://github.com/holepunchto/text-decoder/pull/2

ThaUnknown commented 4 months ago

Moved here https://github.com/holepunchto/text-decoder/pull/2

that is a private org

ThaUnknown commented 4 months ago

This needs a fallback to envs where TextDecoder doesnt exist

I personally struggled to find such envs, I think some very niche stuff like goja doesn't support it, and some smart TV's from 2010's, that's about it tho? I used streamx because of how tiny it was compared to stream, this change kinda nullifies that

mafintosh commented 4 months ago

Open now, was private by mistake

mafintosh commented 4 months ago

We use it on phones where its not there. Dont think 1kb matters personally.

ThaUnknown commented 4 months ago

We use it on phones where its not there. Dont think 1kb matters personally.

ah that makes sense.

yeah, I still don't like the fact that I'm importing packages and functionality which I won't be using, would be nice if this was in a separate class that extended readable/writable, rather than the main one so at least its tree-shakeable, or so I'd like to say, but I'm not sure if CJS would allow that