zlib: add Brotli support by addaleax · Pull Request #24938 · nodejs/node (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation62 Commits8 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

addaleax

Add Brotli support to the zlib module; in particular:

The APIs are identical to the zlib ones, except for the way that some of the more algorithm-specific options are passed to the stream constructor and a missing .params() function (because Brotli does not support that).

This PR is based on @Hackzzila’s #20458, although the internals are quite different, and re-uses more of the existing zlib infrastructure.

Some more visible differences to the main PR are:

Checklist

jdalton, tomscholz, kristoferbaxter, bricss, styfle, tuananh, ginkoid, lucleray, lmammino, yisibl, and 25 more reacted with thumbs up emoji bnb, benjamingr, a0viedo, MDSLKTR, bricss, styfle, tuananh, ginkoid, dbrockman, lmammino, and 14 more reacted with hooray emoji bnb, benjamingr, cb1kenobi, MDSLKTR, nstepien, tomscholz, sindresorhus, bricss, styfle, ginkoid, and 12 more reacted with heart emoji

@addaleax addaleax added zlib

Issues and PRs related to the zlib subsystem.

semver-minor

PRs that contain new features and should be released in the next minor version.

notable-change

PRs with changes that should be highlighted in changelogs.

brotli

Issues and PRs related to the brotli dependency.

labels

Dec 10, 2018

@nodejs-github-bot

@addaleax

mscdex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would much rather this live in a separate module or perhaps in a new namespace (which would still require a new 'module' anyway -- but would be better for organizational purposes) that can house all compression methods. I don't think stuffing this into zlib just so it's semver-minor is the right way to go about things. How the two work or are implemented internally doesn't really matter IMO.

@addaleax

I don't think stuffing this into zlib just so it's semver-minor is the right way to go about things.

As I said in the PR description, that’s not the only reason for this.

How the two work or are implemented internally doesn't really matter IMO.

It does matter that said fact makes the APIs analogous, imo. It also means that a bug or feature request for one part of the API likely applies to the other part of the API as well.

@MylesBorins

For those reviewing you can look at the below subset to avoid seeing the addition of the brotli dep itself

70bb2464c0ca18a35dfe6f2022d05bd8e67817f8...32e89319e19bbbf5cc5632b7da3e3a697bd62487

@kristoferbaxter

Interesting approach, and the API looks quite simple and usable to me.

This would be a great way to address the issue.

@mscdex

It does matter that said fact makes the APIs analogous, imo. It also means that a bug or feature request for one part of the API likely applies to the other part of the API as well.

That's an internal concern though, not something the end user should care about.

Anyway, I still believe we should be doing this more correct from the get-go by incorporating and using a new namespace instead.

@MylesBorins

@mscdex if we move to a new namespace are we imagining compression/zlib and compression/brotli within a node.js namespace? or simply brotli as a separate namespace from zlib?

@jasnell

I'm+1 on the approach suggested by @addaleax. I have to review the code more to sign off tho

@mscdex

@mscdex if we move to a new namespace are we imagining compression/zlib and compression/brotli within a node.js namespace? or simply brotli as a separate namespace from zlib?

I recognize 'compression', 'compress', and similar names are taken in the npm ecosystem, so if the package owners are not ok with node core using those names, I would be ok with something like 'compression/zlib' or similar if we cannot find some other feasible single phrase to use as a namespace. If we cannot come to agreement on that I would at the very least like to see brotli support as a separate module then (e.g. require('brotli')).

@nstepien

Would it make sense to avoid overlapping with existing npm packages by using special characters?

or use a different method maybe:

require.internal('brotli'); require.stdlib('brotli');

@MylesBorins

@MayhemYDG please take a look at #21551 where we are exploring introducing a Node.js namespace in which we can put future modules. This would solve the problem in a slightly more elegant way imho

@mscdex would you be open to landing this within the zlib namespace if we have a specific action plan for improving the API once namespaces land?

I'd like to propose we do the following

@addaleax

make zlib and brotli as their own modules with compression e.g. compression.zlib, compression.brotli

That sounds like replicating the original mistake here – we shouldn’t be naming anything zlib or brotli in order to refer to libraries. Once we have the namespace issue resolved somehow, it would imo be better to just alias our current zlib to a nodejs-namespaced compression module; but then again, that seems a bit pointless if we also provide a nodejs-namespaced zlib module for compatibiliy (which I imagine we might want to do for all core modules)…?

@MylesBorins

@addaleax I've updated the above plan to rename zlib and add a deprecation warning to the compat alias.

@mscdex

@mscdex would you be open to landing this within the zlib namespace if we have a specific action plan for improving the API once namespaces land?

No, as that is something that would probably happen eventually anyway if namespaces do get added.

@jasnell

One approach moving forward could be:

  1. Introduce a new node:compression module that is essentially the current zlib module
  2. Land brotli into node:compression
  3. Make zlib and alias for node:compression
  4. Eventually, deprecate zlib.

@addaleax

@mscdex Instead of just saying that the reasons I provided for putting this feature in zlib in the current situation are invalid, could you give a reason not to do so?

@mscdex

@mscdex Instead of just saying that the reasons I provided for putting this feature in zlib in the current situation are invalid, could you give a reason not to do so?

I hinted at this initially, but I believe it's confusing/misleading and not the correct place for this new API from an organizational standpoint since brotli is not zlib-compatible nor is it a format supported by the standard zlib library. Is that what you were asking for?

@addaleax

@mscdex Okay – I’m not convinced by this, tbh… none of the other formats under zlib are mutually compatible; and like you said yourself, people shouldn’t care what the underlying libraries are, so we can as well act as if zlib provided this algorithm?

Again, I understand that it’s unfortunate that the module was named zlib, but I think it would be more confusing for users to group almost identical APIs with almost identical functionality in different modules…

@mscdex

none of the other formats under zlib are mutually compatible

The formats supported by node are all supported by the actual underlying zlib library, so it makes sense that they're available under the 'zlib' module. It also makes sense because a format like gzip utilizes zlib for its compression/decompression. brotli does not utilize zlib in any way.

but I think it would be more confusing for users to group almost identical APIs with almost identical functionality in different modules

I also prefer that they all live under one module/namespace. I just believe that 'zlib' should not be that module/namespace.

@addaleax

/cc @nodejs/collaborators for opinions on the naming & reviews

mcollina

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jkrems

I don't think most people who use the zlib module necessarily know which compression formats are supported by the "real" zlib or would ever run into issues because of the naming confusion. As such it seems weird to make users jump through additional hoops just because some people know precisely which algorithms are implemented by the C library of the same name.

Renaming it longer term to @nodejs/compress sounds like good cleanup but I'd be +1 to landing it in gzip as-is to make sure people can use it and find it easily.

addaleax pushed a commit to addaleax/node that referenced this pull request

May 13, 2019

@Hackzzila @addaleax

PR-URL: nodejs#24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

addaleax added a commit to addaleax/node that referenced this pull request

May 13, 2019

@addaleax

Refs: nodejs#20458

Co-authored-by: Hackzzila admin@hackzzila.com

PR-URL: nodejs#24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

addaleax added a commit to addaleax/node that referenced this pull request

May 13, 2019

@addaleax

Co-authored-by: Hackzzila admin@hackzzila.com

PR-URL: nodejs#24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

addaleax added a commit to addaleax/node that referenced this pull request

May 13, 2019

@addaleax

PR-URL: nodejs#24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@Hackzzila @MylesBorins

Co-authored-by: Anna Henningsen anna@addaleax.net

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@Hackzzila @MylesBorins

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@addaleax @MylesBorins

Refs: #20458

Co-authored-by: Hackzzila admin@hackzzila.com

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@addaleax @MylesBorins

Co-authored-by: Hackzzila admin@hackzzila.com

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@addaleax @MylesBorins

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@Hackzzila @MylesBorins

Co-authored-by: Anna Henningsen anna@addaleax.net

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@Hackzzila @MylesBorins

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@addaleax @MylesBorins

Refs: #20458

Co-authored-by: Hackzzila admin@hackzzila.com

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@addaleax @MylesBorins

Co-authored-by: Hackzzila admin@hackzzila.com

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

MylesBorins pushed a commit that referenced this pull request

May 16, 2019

@addaleax @MylesBorins

Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater ruben@bridgewater.de Reviewed-By: Matteo Collina matteo.collina@gmail.com Reviewed-By: Jan Krems jan.krems@gmail.com Reviewed-By: James M Snell jasnell@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Daniel Bevenius daniel.bevenius@gmail.com

BethGriggs added a commit that referenced this pull request

May 28, 2019

@BethGriggs

Notable changes:

PR-URL: #27514

BethGriggs added a commit that referenced this pull request

May 28, 2019

@BethGriggs

Notable changes:

PR-URL: #27514

BethGriggs added a commit that referenced this pull request

May 28, 2019

@BethGriggs

Notable changes:

PR-URL: #27514

This was referenced

May 29, 2019

@aam1r aam1r mentioned this pull request

Jun 12, 2020

Reviewers

@vsemozhetbyt vsemozhetbyt vsemozhetbyt left review comments

@mscdex mscdex mscdex requested changes

@mcollina mcollina mcollina approved these changes

@ofrobots ofrobots ofrobots approved these changes

@danbev danbev danbev approved these changes

@jasnell jasnell jasnell approved these changes

@MylesBorins MylesBorins MylesBorins approved these changes

@jkrems jkrems jkrems approved these changes

@BridgeAR BridgeAR BridgeAR approved these changes

@Hackzzila Hackzzila Hackzzila approved these changes

Labels

brotli

Issues and PRs related to the brotli dependency.

meta

Issues and PRs related to the general management of the project.

notable-change

PRs with changes that should be highlighted in changelogs.

semver-minor

PRs that contain new features and should be released in the next minor version.

zlib

Issues and PRs related to the zlib subsystem.