Skip to content

Commit 197a465

Browse files
committed
zlib: move constants into zlib.constants
zlib constants were previously being added to binding in node_zlib.cc. This moves the zlib constants to node_constants.cc for consistency with the recent constants refactoring: #6534 Adds require('zlib').constants to expose the constants Docs-only deprecates the constants hung directly off require('zlib') Removes a couple constants from the docs that apparently no longer exist in the code PR-URL: #7203 Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent a173483 commit 197a465

11 files changed

+207
-177
lines changed

doc/api/zlib.md

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ method that is used to compressed the last chunk of input data:
123123
// This is a truncated version of the buffer from the above examples
124124
const buffer = Buffer.from('eJzT0yMA', 'base64');
125125

126-
zlib.unzip(buffer, { finishFlush: zlib.Z_SYNC_FLUSH }, (err, buffer) => {
126+
zlib.unzip(buffer,
127+
{finishFlush: zlib.constants.Z_SYNC_FLUSH},
128+
(err, buffer) => {
127129
if (!err) {
128130
console.log(buffer.toString());
129131
} else {
@@ -221,65 +223,56 @@ added: v0.5.8
221223

222224
<!--type=misc-->
223225

224-
All of the constants defined in `zlib.h` are also defined on `require('zlib')`.
225-
In the normal course of operations, it will not be necessary to use these
226-
constants. They are documented so that their presence is not surprising. This
227-
section is taken almost directly from the [zlib documentation][]. See
228-
<http://zlib.net/manual.html#Constants> for more details.
226+
All of the constants defined in `zlib.h` are also defined on
227+
`require('zlib').constants`. In the normal course of operations, it will not be
228+
necessary to use these constants. They are documented so that their presence is
229+
not surprising. This section is taken almost directly from the
230+
[zlib documentation][]. See <http://zlib.net/manual.html#Constants> for more
231+
details.
232+
233+
*Note*: Previously, the constants were available directly from
234+
`require('zlib')`, for instance `zlib.Z_NO_FLUSH`. Accessing the constants
235+
directly from the module is currently still possible but should be considered
236+
deprecated.
229237

230238
Allowed flush values.
231239

232-
* `zlib.Z_NO_FLUSH`
233-
* `zlib.Z_PARTIAL_FLUSH`
234-
* `zlib.Z_SYNC_FLUSH`
235-
* `zlib.Z_FULL_FLUSH`
236-
* `zlib.Z_FINISH`
237-
* `zlib.Z_BLOCK`
238-
* `zlib.Z_TREES`
240+
* `zlib.constants.Z_NO_FLUSH`
241+
* `zlib.constants.Z_PARTIAL_FLUSH`
242+
* `zlib.constants.Z_SYNC_FLUSH`
243+
* `zlib.constants.Z_FULL_FLUSH`
244+
* `zlib.constants.Z_FINISH`
245+
* `zlib.constants.Z_BLOCK`
246+
* `zlib.constants.Z_TREES`
239247

240248
Return codes for the compression/decompression functions. Negative
241249
values are errors, positive values are used for special but normal
242250
events.
243251

244-
* `zlib.Z_OK`
245-
* `zlib.Z_STREAM_END`
246-
* `zlib.Z_NEED_DICT`
247-
* `zlib.Z_ERRNO`
248-
* `zlib.Z_STREAM_ERROR`
249-
* `zlib.Z_DATA_ERROR`
250-
* `zlib.Z_MEM_ERROR`
251-
* `zlib.Z_BUF_ERROR`
252-
* `zlib.Z_VERSION_ERROR`
252+
* `zlib.constants.Z_OK`
253+
* `zlib.constants.Z_STREAM_END`
254+
* `zlib.constants.Z_NEED_DICT`
255+
* `zlib.constants.Z_ERRNO`
256+
* `zlib.constants.Z_STREAM_ERROR`
257+
* `zlib.constants.Z_DATA_ERROR`
258+
* `zlib.constants.Z_MEM_ERROR`
259+
* `zlib.constants.Z_BUF_ERROR`
260+
* `zlib.constants.Z_VERSION_ERROR`
253261

254262
Compression levels.
255263

256-
* `zlib.Z_NO_COMPRESSION`
257-
* `zlib.Z_BEST_SPEED`
258-
* `zlib.Z_BEST_COMPRESSION`
259-
* `zlib.Z_DEFAULT_COMPRESSION`
264+
* `zlib.constants.Z_NO_COMPRESSION`
265+
* `zlib.constants.Z_BEST_SPEED`
266+
* `zlib.constants.Z_BEST_COMPRESSION`
267+
* `zlib.constants.Z_DEFAULT_COMPRESSION`
260268

261269
Compression strategy.
262270

263-
* `zlib.Z_FILTERED`
264-
* `zlib.Z_HUFFMAN_ONLY`
265-
* `zlib.Z_RLE`
266-
* `zlib.Z_FIXED`
267-
* `zlib.Z_DEFAULT_STRATEGY`
268-
269-
Possible values of the data_type field.
270-
271-
* `zlib.Z_BINARY`
272-
* `zlib.Z_TEXT`
273-
* `zlib.Z_ASCII`
274-
* `zlib.Z_UNKNOWN`
275-
276-
The deflate compression method (the only one supported in this version).
277-
278-
* `zlib.Z_DEFLATED`
279-
280-
For initializing zalloc, zfree, opaque.
281-
282-
* `zlib.Z_NULL`
271+
* `zlib.constants.Z_FILTERED`
272+
* `zlib.constants.Z_HUFFMAN_ONLY`
273+
* `zlib.constants.Z_RLE`
274+
* `zlib.constants.Z_FIXED`
275+
* `zlib.constants.Z_DEFAULT_STRATEGY`
283276

284277
## Class Options
285278
<!-- YAML
@@ -293,8 +286,8 @@ Each class takes an `options` object. All options are optional.
293286
Note that some options are only relevant when compressing, and are
294287
ignored by the decompression classes.
295288

296-
* `flush` (default: `zlib.Z_NO_FLUSH`)
297-
* `finishFlush` (default: `zlib.Z_FINISH`)
289+
* `flush` (default: `zlib.constants.Z_NO_FLUSH`)
290+
* `finishFlush` (default: `zlib.constants.Z_FINISH`)
298291
* `chunkSize` (default: 16*1024)
299292
* `windowBits`
300293
* `level` (compression only)
@@ -368,7 +361,7 @@ class of the compressor/decompressor classes.
368361
added: v0.5.8
369362
-->
370363

371-
`kind` defaults to `zlib.Z_FULL_FLUSH`.
364+
`kind` defaults to `zlib.constants.Z_FULL_FLUSH`.
372365

373366
Flush pending data. Don't call this frivolously, premature flushes negatively
374367
impact the effectiveness of the compression algorithm.
@@ -391,6 +384,10 @@ Only applicable to deflate algorithm.
391384
added: v0.7.0
392385
-->
393386

387+
## zlib.constants
388+
389+
Provides an object enumerating Zlib-related [constants][].
390+
394391
Reset the compressor/decompressor to factory defaults. Only applicable to
395392
the inflate and deflate algorithms.
396393

@@ -545,3 +542,4 @@ Decompress a Buffer or string with Unzip.
545542
[Unzip]: #zlib_class_zlib_unzip
546543
[`.flush()`]: #zlib_zlib_flush_kind_callback
547544
[Buffer]: buffer.html
545+
[constants]: #constants_constants

0 commit comments

Comments
 (0)