-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
zlib: add ArrayBuffer support #16042
Conversation
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'll have to run this through CI before landing, but CI is currently busy with the 220+ code+learn PRs... so let's wait a bit.
doc/api/zlib.md
Outdated
@@ -308,7 +311,7 @@ ignored by the decompression classes. | |||
* `level` {integer} (compression only) | |||
* `memLevel` {integer} (compression only) | |||
* `strategy` {integer} (compression only) | |||
* `dictionary` {Buffer|TypedArray|DataView} (deflate/inflate only, empty dictionary by | |||
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer} (deflate/inflate only, empty dictionary by |
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.
Looks like this line might exceed 80 characters... either you can re-wrap, or we can do it while landing this.
src/util.h
Outdated
v8::ArrayBuffer::Contents name##_c = name->GetContents(); \ | ||
name##_length = name##_c.ByteLength(); \ | ||
name##_data = \ | ||
static_cast<char*>(name##_c.Data()); \ |
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.
These two lines can be joined into one. Again, it would be great if you could fix that, but if not we can fix that while landing.
lib/zlib.js
Outdated
@@ -238,7 +241,7 @@ function Zlib(opts, mode) { | |||
} | |||
|
|||
dictionary = opts.dictionary; | |||
if (dictionary !== undefined && !isArrayBufferView(dictionary)) { | |||
if (dictionary !== undefined && !isArrayBufferView(dictionary) && !isAnyArrayBuffer(dictionary)) { |
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.
This line needs to be wrapped at 80 characters as well.
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.
LGTM
I know this is tricky, but can we actually split the non-zlib changes into its own commit? Can happen while landing as well :)
I addressed those couple of line length issues. Is there a code style guide somewhere that I should reference in the future? (I just ran my changes through eslint to get an idea of what to change.) @addaleax did you link to some CI issues there? Looks like some failures. I had a glance but am not certain about the output there. Also: when you suggested splitting were you talking the C++ code for the ArrayBuffers? Big thanks to @TimothyGu for holding my hand during my updating those; however I thought the work was pretty interrelated? If you want that part split, can it happen "during landing" as you suggested. |
@JemBijoux I started CI jobs for this, yes. The failures look like this: assert.js:45
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: 'The "buffer" argument must be one of type string, Buffer, TypedArray, DataView, or ArrayBuffer' === 'The "buffer" argument must be one of type string, Buffer, TypedArray, or DataView'
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/common/index.js:723:16)
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/common/index.js:517:15)
at expectedException (assert.js:651:19)
at innerThrows (assert.js:685:21)
at Function.throws (assert.js:702:3)
at Object.expectsError (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/common/index.js:745:12)
at __dirname.forEach (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/parallel/test-zlib-not-string-or-buffer.js:10:10)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/parallel/test-zlib-not-string-or-buffer.js:9:65)
at Module._compile (module.js:600:30) Can you reproduce those by running And, what I’m basically thinking is that the changes to |
Hey! So I was able to confirm the issue with the test and make that fix no problem. All tests passing again. I also moved that node_buffer.cc file into it's own commit now (#16111). However, when I did that, one of the changes to a test I had here started to fail also in |
I think this is ready to land. Ping @TimothyGu |
@BridgeAR See also the discussion in #16111 … I am not quite at the point where I think extending the Buffer code for this is necessarily a great idea … I think for now it might be nicer to let this be a zlib-only thing and create an Uint8Array for passed ArrayBuffers, then work with that, if we want support? |
I see. In that case I just mark this accordingly for now. Thanks for the heads up! |
I'm a little unsure what the situation is here. What would have to happen for this to get unblocked? |
This is blocked on #16111, that’s all. I think for zlib this might make more sense than for the general case of all Buffer-taking APIs (although “compress a chunk of memory” is still going to be exceedingly rare compared to “compress a chunk of data”, conceptually). It might be a nicer approach to create a |
PR-URL: nodejs#16042 Refs: nodejs#1826 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Landed in 2848718 🎉 |
PR-URL: #16042 Refs: #1826 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Notable change: * async_hooks: - deprecate AsyncHooks Sensitive API and runInAsyncIdScope. Neither API were documented. (Andreas Madsen) #16972 * deps: - update nghttp2 to 1.29.0 (James M Snell) #17908 - upgrade npm to 5.6.0 (Kat Marchán) #17535 - cherry-pick 50f7455 from upstream V8 (Michaël Zasso) #16591 * events: - remove reaches into _events internals (Anatoli Papirovski) #17440 * http: - add rawPacket in err of `clientError` event (XadillaX) #17672 * http2: - implement maxSessionMemory (James M Snell) #17967 - add initial support for originSet (James M Snell) #17935 - add altsvc support (James M Snell) #17917 - perf_hooks integration (James M Snell) #17906 * net: - remove Socket.prototype.write (Anna Henningsen) #17644 - remove Socket.prototype.listen (Ruben Bridgewater) #13735 * repl: - show lexically scoped vars in tab completion (Michaël Zasso) #16591 * stream: - rm {writeable/readable}State.length (Calvin Metcalf) #12857 - add flow and buffer properties to streams (Calvin Metcalf) #12855 * util: - allow wildcards in NODE_DEBUG variable (Tyler) #17609 * zlib: - add ArrayBuffer support (Jem Bezooyen) #16042 * Addedew collaborator** - [starkwang](https://github.com/starkwang) Weijia Wang * Addedew TSC member** - [danbev](https://github.com/danbev) Daniel Bevenius PR-URL: #18069
Notable change: * async_hooks: - deprecate AsyncHooks Sensitive API and runInAsyncIdScope. Neither API were documented. (Andreas Madsen) #16972 * deps: - update nghttp2 to 1.29.0 (James M Snell) #17908 - upgrade npm to 5.6.0 (Kat Marchán) #17535 - cherry-pick 50f7455 from upstream V8 (Michaël Zasso) #16591 * events: - remove reaches into _events internals (Anatoli Papirovski) #17440 * http: - add rawPacket in err of `clientError` event (XadillaX) #17672 * http2: - implement maxSessionMemory (James M Snell) #17967 - add initial support for originSet (James M Snell) #17935 - add altsvc support (James M Snell) #17917 - perf_hooks integration (James M Snell) #17906 - Refactoring and cleanup of Http2Session and Http2Stream destroy (James M Snell) #17406 * net: - remove Socket.prototype.write (Anna Henningsen) #17644 - remove Socket.prototype.listen (Ruben Bridgewater) #13735 * repl: - show lexically scoped vars in tab completion (Michaël Zasso) #16591 * stream: - rm {writeable/readable}State.length (Calvin Metcalf) #12857 - add flow and buffer properties to streams (Calvin Metcalf) #12855 * util: - allow wildcards in NODE_DEBUG variable (Tyler) #17609 * zlib: - add ArrayBuffer support (Jem Bezooyen) #16042 * Addedew collaborator** - [starkwang](https://github.com/starkwang) Weijia Wang * Addedew TSC member** - [danbev](https://github.com/danbev) Daniel Bevenius PR-URL: #18069
Notable change: * async_hooks: - deprecate AsyncHooks Sensitive API and runInAsyncIdScope. Neither API were documented. (Andreas Madsen) #16972 * deps: - update nghttp2 to 1.29.0 (James M Snell) #17908 - upgrade npm to 5.6.0 (Kat Marchán) #17535 - cherry-pick 50f7455 from upstream V8 (Michaël Zasso) #16591 * events: - remove reaches into _events internals (Anatoli Papirovski) #17440 * http: - add rawPacket in err of `clientError` event (XadillaX) #17672 * http2: - implement maxSessionMemory (James M Snell) #17967 - add initial support for originSet (James M Snell) #17935 - add altsvc support (James M Snell) #17917 - perf_hooks integration (James M Snell) #17906 - Refactoring and cleanup of Http2Session and Http2Stream destroy (James M Snell) #17406 * net: - remove Socket.prototype.write (Anna Henningsen) #17644 - remove Socket.prototype.listen (Ruben Bridgewater) #13735 * repl: - show lexically scoped vars in tab completion (Michaël Zasso) #16591 * stream: - rm {writeable/readable}State.length (Calvin Metcalf) #12857 - add flow and buffer properties to streams (Calvin Metcalf) #12855 * util: - allow wildcards in NODE_DEBUG variable (Tyler) #17609 * zlib: - add ArrayBuffer support (Jem Bezooyen) #16042 * Addedew collaborator** - [starkwang](https://github.com/starkwang) Weijia Wang * Addedew TSC member** - [danbev](https://github.com/danbev) Daniel Bevenius PR-URL: #18069
Would we want to backport to v8.x? If so this will need a manual backport |
Refs: #1826
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
zlib, src