FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

brotli: add brotli support by Hackzzila · Pull Request #20458 · nodejs/node · GitHub

/ node Public

brotli: add brotli support - #20458

Closed
Hackzzila wants to merge 11 commits into
nodejs:masterfrom
Hackzzila:brotli-dev
Closed

brotli: add brotli support#20458
Hackzzila wants to merge 11 commits into
nodejs:masterfrom
Hackzzila:brotli-dev

Conversation

Copy link
Copy Markdown
Contributor

Fixes: #18964

Adds brotli support to core. The brotli module must be enabled with --expose-brotli. The api, and most of the source code, is almost identical to the zlib module.

There are a few things that need polishing but I thought I would open this up for discussion.

/cc @MylesBorins

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

addaleax commented May 1, 2018

Copy link
Copy Markdown
Member

The api, and most of the source code, is almost identical to the zlib module.

Do you think it would be possible to work on re-using as much code as possible? I think that would be a very good idea if we can make it work (because it’s going to happen eventually anyway).

devsnek commented May 1, 2018
edited
Loading

Copy link
Copy Markdown
Member

without overstepping this pr too much, maybe we can take this opportunity to think of a new way to group our compression stuff, both in terms of source and namespace (require('compression/brotli') or something)

vsemozhetbyt added the semver-minor PRs that contain new features and should be released in the next minor version. label May 1, 2018

vsemozhetbyt commented May 1, 2018
edited
Loading

Copy link
Copy Markdown
Contributor

As per Introducing New Modules policy, beware:

https://www.npmjs.com/package/brotli

devsnek commented May 1, 2018

Copy link
Copy Markdown
Member

cc @devongovett

Hackzzila commented May 1, 2018
edited
Loading

Copy link
Copy Markdown
Contributor Author

As per Introducing New Modules policy, beware:

I managed to miss that, I can talk to the author but maybe this could be moved under a scope as brought up in nodejs/TSC#389

Copy link
Copy Markdown
Contributor

hey guys, I'm the owner of brotli on npm. That package is a hand coded decoder + emscripten ported encoder which both work in the browser as well as node. I'd be happy to make the package's API compatible with whatever API node decides on and use it as a browserify-style port so it can be used in the browser. WDYT?

vsemozhetbyt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Doc part LGTM with some nits. Sorry for a big bunch of them)

And thank you!

Comment thread doc/api/cli.md
@@ -81,6 +81,10 @@ added: v9.6.0

Enable experimental ES Module support in the `vm` module.

### `--expose-brotli`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should we add metadata?

<!-- YAML
 added: REPLACEME
-->

Hackzzila May 1, 2018
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I didn't know what I should put there so I just removed those. Should they just be set to like v10.x.x? Or I guess REPLACEME works too :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

also with our pattern i think it should be --experimental-brotli

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If I recall correctly, REPLACEME has some part in build automation as a do-not-forget-to-replace guard)

Comment thread doc/api/brotli.md
@@ -0,0 +1,404 @@
# Brotli

This comment was marked as resolved.

Comment thread doc/api/brotli.md Outdated

## Threadpool Usage

Note that all brotli APIs except those that are explicitly synchronous use

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

brotli APIs -> `brotli` APIs?

Comment thread doc/api/brotli.md Outdated
content-encoding mechanism defined by
[HTTP](https://tools.ietf.org/html/rfc7230#section-4.2).

The HTTP [`Accept-Encoding`][] header is used within an http request to identify

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

http request -> HTTP request or `http` request?

Comment thread doc/api/brotli.md Outdated

// Note: This is not a conformant accept-encoding parser.
// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
// Note: A quality of 4 is a good balace of speed and quality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

balace ->balance?

Comment thread doc/api/brotli.md
Error codes for decompression operations.

## brotli.constants

This comment was marked as resolved.

Comment thread doc/api/brotli.md Outdated
to supply options to the `brotli` classes and will call the supplied callback
with `callback(error, result)`.

Every method has a `*Sync` counterpart, which accept the same arguments, but

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

accept -> accepts?

Comment thread doc/api/brotli.md Outdated
Every method has a `*Sync` counterpart, which accept the same arguments, but
without a callback.

### brotli.compress(buffer[, options][, callback])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If it can be a string, then buffer -> data here and below?

Comment thread doc/api/brotli.md Outdated
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}

Decompress a chunk of data with [Decompress][].
If callback is omitted a Promise will be returned.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Promise -> `Promise` or even {Promise} (will be linkified)?
Ditto below.

Comment thread doc/api/brotli.md Outdated

- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}

Decompress a chunk of data with [Decompress][].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Compress a chunk of data with [Compress][].

Copy link
Copy Markdown
Contributor Author

@vsemozhetbyt a few of the things you mentioned also apply to the zlib docs, those should probably be looked over sometime as well.

Comment thread doc/api/brotli.md Outdated

Compress a stream.

### new brotli.Compress(options)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[options]?

Comment thread doc/api/brotli.md Outdated

Decompress a stream.

### new brotli.Decompress(options)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

[options]?

Comment thread doc/api/brotli.md Outdated
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
[`brotli/encode.h`]: https://github.com/google/brotli/blob/v1.0.4/c/include/brotli/encode.h
[`brotli/decode.h`]: https://github.com/google/brotli/blob/v1.0.4/c/include/brotli/decode.h

vsemozhetbyt May 1, 2018
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We usually sort bottom references in ASCII order, so this should go before the [`brotli/encode.h`]:.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

References below also need some resorting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Don't know how I managed to mess up sorting 😆

Copy link
Copy Markdown
Contributor

@vsemozhetbyt a few of the things you mentioned also apply to the zlib docs, those should probably be looked over sometime as well.

Yeah, our docs are far from ideal, but we are working on them)

Copy link
Copy Markdown
Contributor

I will go ahead and create brotli label)

Comment thread doc/api/brotli.md Outdated

// Note: This is not a conformant accept-encoding parser.
// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
// Note: A quality of 4 is a good balace of speed and quality.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I believe «Note: » prefixes were removed from the docs earlier in #18592.
Are those needed here?

Copy link
Copy Markdown
Contributor Author

@vsemozhetbyt thanks for the docs review! Hopefully I have fixed everything now.

Comment thread doc/api/brotli.md Outdated
if (!acceptEncoding) {
acceptEncoding = '';
}
let acceptEncoding = request.headers['accept-encoding'] || '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

May be const now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If only eslint for vscode checked markdown too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can eslint-plugin-markdown be of any help? We use it in CI and local linting.

Also, you can just run from the project root for linting code fragments in docs:

node tools/node_modules/eslint/bin/eslint.js --ext=.md doc

Comment thread doc/api/brotli.md Outdated
[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
[`brotli/encode.h`]: https://github.com/google/brotli/blob/v1.0.4/c/include/brotli/encode.h
[`brotli.constants`]: #brotli_constants

vsemozhetbyt May 2, 2018
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If this intended to refer brotli.constants property (and not just "Constants" section), then this should be #brotli_brotli_constants.

Copy link
Copy Markdown
Contributor Author

Do you think it would be possible to work on re-using as much code as possible? I think that would be a very good idea if we can make it work (because it’s going to happen eventually anyway).

I am unsure how this would be done for the C++ code, but it might be worth a shot for the JS.

Comment thread doc/api/brotli.md Outdated
Note that some options are only relevant when compressing, and are
ignored by the decompression classes.
Note that some options are only relevant when compressing or decompressing,
and are simply ignored.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I am not sure, but it seems a bit incomplete or confusing now. Maybe something like "and are simply ignored when inappropriate."?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Something like "and invalid options are simply ignored" should also work.

addaleax self-assigned this Dec 7, 2018
addaleax mentioned this pull request Dec 10, 2018
4 tasks
addaleax added a commit to addaleax/node that referenced this pull request Jan 3, 2019
Refs: nodejs#20458

Co-authored-by: Hackzzila <admin@hackzzila.com>
addaleax added a commit that referenced this pull request Jan 5, 2019
Refs: #20458

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

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>
addaleax added a commit that referenced this pull request Jan 5, 2019
Refs: #20458

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

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>

addaleax commented Jan 5, 2019

Copy link
Copy Markdown
Member

This has been done in #24938! 🎉

addaleax closed this Jan 5, 2019
refack pushed a commit to refack/node that referenced this pull request Jan 14, 2019
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
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>
MylesBorins pushed a commit that referenced this pull request May 16, 2019
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
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>

This comment was marked as spam.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked PRs that are blocked by other issues or PRs. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Idea: Brotli support in core

Back | FazBrowse Home | New Git URL