lucacasonato / proposal-binary-encoding

A proposal to add modern, easy to use binary encoders to the web platform.
Other
40 stars 1 forks source link

Is encouraging binary encoding/decoding a good idea? #4

Open domenic opened 3 years ago

domenic commented 3 years ago

I found the arguments at https://github.com/whatwg/html/issues/6811#issuecomment-870161594 by @Kaiido somewhat persuasive. Basically, if you're encoding your bytes to and from a string, you're probably doing something wrong, and you should instead modify your APIs or endpoints to accept bytes anyway.

There are definitely cases where it's useful, mostly around parsing and serializing older file formats. But I'm not sure they need to be promoted to the web platform (or language).

lucacasonato commented 3 years ago

Hex encoding of digests is a frequent use for binary encodings. Hex encoded SHA-256 digests are very common for integrity checking.

Basically, if you're encoding your bytes to and from a string, you're probably doing something wrong, and you should instead modify your APIs or endpoints to accept bytes anyway.

Many public APIs that I don't personally have the ability to change (including ones from Google and GitHub) require the usage of base64 encoded data in payloads. I disagree that users are thus doing something wrong when using these APIs. Sometimes they are the only choice you have.

There are definitely cases where it's useful, mostly around parsing and serializing older file formats. But I'm not sure they need to be promoted to the web platform (or language).

Essentially every other language and ecosystem has builtin binary encoding. This shows there is a genuine need, and I don't think the web platform is doing anyone a favour by requiring that people include subpar external packages for this usecase. https://www.npmjs.com/package/js-base64 has 5.8 million weekly downloads.