-
Notifications
You must be signed in to change notification settings - Fork 30k
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
brotli: add brotli support #20458
brotli: add brotli support #20458
Conversation
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). |
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 ( |
As per Introducing New Modules policy, beware: |
cc @devongovett |
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 |
hey guys, I'm the owner of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc part LGTM with some nits. Sorry for a big bunch of them)
And thank you!
@@ -81,6 +81,10 @@ added: v9.6.0 | |||
|
|||
Enable experimental ES Module support in the `vm` module. | |||
|
|||
### `--expose-brotli` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add metadata?
<!-- YAML
added: REPLACEME
-->
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also with our pattern i think it should be --experimental-brotli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, REPLACEME
has some part in build automation as a do-not-forget-to-replace guard)
@@ -0,0 +1,404 @@ | |||
# Brotli | |||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
doc/api/brotli.md
Outdated
|
||
## Threadpool Usage | ||
|
||
Note that all brotli APIs except those that are explicitly synchronous use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brotli APIs
-> `brotli` APIs
?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http request
-> HTTP request
or `http` request
?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
balace ->balance?
Error codes for decompression operations. | ||
|
||
## brotli.constants | ||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accept -> accepts?
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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it can be a string, then buffer
-> data
here and below?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise
-> `Promise`
or even {Promise}
(will be linkified)?
Ditto below.
doc/api/brotli.md
Outdated
|
||
- `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string} | ||
|
||
Decompress a chunk of data with [Decompress][]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compress a chunk of data with [Compress][].
@vsemozhetbyt a few of the things you mentioned also apply to the zlib docs, those should probably be looked over sometime as well. |
doc/api/brotli.md
Outdated
|
||
Compress a stream. | ||
|
||
### new brotli.Compress(options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[options]
?
doc/api/brotli.md
Outdated
|
||
Decompress a stream. | ||
|
||
### new brotli.Decompress(options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[options]
?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually sort bottom references in ASCII order, so this should go before the [`brotli/encode.h`]:
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
References below also need some resorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know how I managed to mess up sorting 😆
Yeah, our docs are far from ideal, but we are working on them) |
I will go ahead and create |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe «Note: » prefixes were removed from the docs earlier in #18592.
Are those needed here?
@vsemozhetbyt thanks for the docs review! Hopefully I have fixed everything now. |
doc/api/brotli.md
Outdated
if (!acceptEncoding) { | ||
acceptEncoding = ''; | ||
} | ||
let acceptEncoding = request.headers['accept-encoding'] || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be const
now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only eslint for vscode checked markdown too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this intended to refer brotli.constants
property (and not just "Constants" section), then this should be #brotli_brotli_constants
.
I am unsure how this would be done for the C++ code, but it might be worth a shot for the JS. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, but it seems a bit incomplete or confusing now. Maybe something like "and are simply ignored when inappropriate."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like "and invalid options are simply ignored" should also work.
Refs: nodejs#20458 Co-authored-by: Hackzzila <[email protected]>
Refs: #20458 Co-authored-by: Hackzzila <[email protected]> PR-URL: #24938 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
Refs: #20458 Co-authored-by: Hackzzila <[email protected]> PR-URL: #24938 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
This has been done in #24938! 🎉 |
Refs: nodejs#20458 Co-authored-by: Hackzzila <[email protected]> PR-URL: nodejs#24938 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
Refs: nodejs#20458 Co-authored-by: Hackzzila <[email protected]> PR-URL: nodejs#24938 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
Refs: #20458 Co-authored-by: Hackzzila <[email protected]> Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
Refs: #20458 Co-authored-by: Hackzzila <[email protected]> Backport-PR-URL: #27681 PR-URL: #24938 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
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), orvcbuild test
(Windows) passes