Skip to content

Commit

Permalink
zlib: move constants into zlib.constants
Browse files Browse the repository at this point in the history
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 <rod@vagg.org>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
jasnell committed Jun 12, 2016
1 parent a173483 commit 197a465
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 177 deletions.
96 changes: 47 additions & 49 deletions doc/api/zlib.md
Expand Up @@ -123,7 +123,9 @@ method that is used to compressed the last chunk of input data:
// This is a truncated version of the buffer from the above examples
const buffer = Buffer.from('eJzT0yMA', 'base64');

zlib.unzip(buffer, { finishFlush: zlib.Z_SYNC_FLUSH }, (err, buffer) => {
zlib.unzip(buffer,
{finishFlush: zlib.constants.Z_SYNC_FLUSH},
(err, buffer) => {
if (!err) {
console.log(buffer.toString());
} else {
Expand Down Expand Up @@ -221,65 +223,56 @@ added: v0.5.8

<!--type=misc-->

All of the constants defined in `zlib.h` are also defined on `require('zlib')`.
In the normal course of operations, it will not be necessary to use these
constants. They are documented so that their presence is not surprising. This
section is taken almost directly from the [zlib documentation][]. See
<http://zlib.net/manual.html#Constants> for more details.
All of the constants defined in `zlib.h` are also defined on
`require('zlib').constants`. In the normal course of operations, it will not be
necessary to use these constants. They are documented so that their presence is
not surprising. This section is taken almost directly from the
[zlib documentation][]. See <http://zlib.net/manual.html#Constants> for more
details.

*Note*: Previously, the constants were available directly from
`require('zlib')`, for instance `zlib.Z_NO_FLUSH`. Accessing the constants
directly from the module is currently still possible but should be considered
deprecated.

Allowed flush values.

* `zlib.Z_NO_FLUSH`
* `zlib.Z_PARTIAL_FLUSH`
* `zlib.Z_SYNC_FLUSH`
* `zlib.Z_FULL_FLUSH`
* `zlib.Z_FINISH`
* `zlib.Z_BLOCK`
* `zlib.Z_TREES`
* `zlib.constants.Z_NO_FLUSH`
* `zlib.constants.Z_PARTIAL_FLUSH`
* `zlib.constants.Z_SYNC_FLUSH`
* `zlib.constants.Z_FULL_FLUSH`
* `zlib.constants.Z_FINISH`
* `zlib.constants.Z_BLOCK`
* `zlib.constants.Z_TREES`

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

* `zlib.Z_OK`
* `zlib.Z_STREAM_END`
* `zlib.Z_NEED_DICT`
* `zlib.Z_ERRNO`
* `zlib.Z_STREAM_ERROR`
* `zlib.Z_DATA_ERROR`
* `zlib.Z_MEM_ERROR`
* `zlib.Z_BUF_ERROR`
* `zlib.Z_VERSION_ERROR`
* `zlib.constants.Z_OK`
* `zlib.constants.Z_STREAM_END`
* `zlib.constants.Z_NEED_DICT`
* `zlib.constants.Z_ERRNO`
* `zlib.constants.Z_STREAM_ERROR`
* `zlib.constants.Z_DATA_ERROR`
* `zlib.constants.Z_MEM_ERROR`
* `zlib.constants.Z_BUF_ERROR`
* `zlib.constants.Z_VERSION_ERROR`

Compression levels.

* `zlib.Z_NO_COMPRESSION`
* `zlib.Z_BEST_SPEED`
* `zlib.Z_BEST_COMPRESSION`
* `zlib.Z_DEFAULT_COMPRESSION`
* `zlib.constants.Z_NO_COMPRESSION`
* `zlib.constants.Z_BEST_SPEED`
* `zlib.constants.Z_BEST_COMPRESSION`
* `zlib.constants.Z_DEFAULT_COMPRESSION`

Compression strategy.

* `zlib.Z_FILTERED`
* `zlib.Z_HUFFMAN_ONLY`
* `zlib.Z_RLE`
* `zlib.Z_FIXED`
* `zlib.Z_DEFAULT_STRATEGY`

Possible values of the data_type field.

* `zlib.Z_BINARY`
* `zlib.Z_TEXT`
* `zlib.Z_ASCII`
* `zlib.Z_UNKNOWN`

The deflate compression method (the only one supported in this version).

* `zlib.Z_DEFLATED`

For initializing zalloc, zfree, opaque.

* `zlib.Z_NULL`
* `zlib.constants.Z_FILTERED`
* `zlib.constants.Z_HUFFMAN_ONLY`
* `zlib.constants.Z_RLE`
* `zlib.constants.Z_FIXED`
* `zlib.constants.Z_DEFAULT_STRATEGY`

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

* `flush` (default: `zlib.Z_NO_FLUSH`)
* `finishFlush` (default: `zlib.Z_FINISH`)
* `flush` (default: `zlib.constants.Z_NO_FLUSH`)
* `finishFlush` (default: `zlib.constants.Z_FINISH`)
* `chunkSize` (default: 16*1024)
* `windowBits`
* `level` (compression only)
Expand Down Expand Up @@ -368,7 +361,7 @@ class of the compressor/decompressor classes.
added: v0.5.8
-->

`kind` defaults to `zlib.Z_FULL_FLUSH`.
`kind` defaults to `zlib.constants.Z_FULL_FLUSH`.

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

## zlib.constants

Provides an object enumerating Zlib-related [constants][].

Reset the compressor/decompressor to factory defaults. Only applicable to
the inflate and deflate algorithms.

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

0 comments on commit 197a465

Please sign in to comment.