summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2016-04-06 00:54:34 +0200
committerJames M Snell <jasnell@gmail.com>2016-04-26 12:16:09 -0700
commit5f11b5369428988f32303eae02410c78a0b8278f (patch)
treed2f9162069cc539abee030ce7c14d99fcc6134b3 /test
parentf170aa6c14bc4b3d4030258f034c1f8b0ae5c8e9 (diff)
downloadnode-new-5f11b5369428988f32303eae02410c78a0b8278f.tar.gz
zlib: Make the finish flush flag configurable
Up to now, `Z_FINISH` was always the flushing flag that was used for the last chunk of input data. This patch makes this choice configurable so that advanced users can perform e.g. decompression of partial data using `Z_SYNC_FLUSH`, if that suits their needs. Add tests to make sure that an error is thrown upon encountering invalid `flush` or `finishFlush` flags. Fixes: https://github.com/nodejs/node/issues/5761 PR-URL: https://github.com/nodejs/node/pull/6069 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-zlib-flush-flags.js28
-rw-r--r--test/parallel/test-zlib-truncated.js17
2 files changed, 45 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-flush-flags.js b/test/parallel/test-zlib-flush-flags.js
new file mode 100644
index 0000000000..08c79f138b
--- /dev/null
+++ b/test/parallel/test-zlib-flush-flags.js
@@ -0,0 +1,28 @@
+'use strict';
+require('../common');
+const assert = require('assert');
+const zlib = require('zlib');
+
+assert.doesNotThrow(() => {
+ zlib.createGzip({ flush: zlib.Z_SYNC_FLUSH });
+});
+
+assert.throws(() => {
+ zlib.createGzip({ flush: 'foobar' });
+}, /Invalid flush flag: foobar/);
+
+assert.throws(() => {
+ zlib.createGzip({ flush: 10000 });
+}, /Invalid flush flag: 10000/);
+
+assert.doesNotThrow(() => {
+ zlib.createGzip({ finishFlush: zlib.Z_SYNC_FLUSH });
+});
+
+assert.throws(() => {
+ zlib.createGzip({ finishFlush: 'foobar' });
+}, /Invalid flush flag: foobar/);
+
+assert.throws(() => {
+ zlib.createGzip({ finishFlush: 10000 });
+}, /Invalid flush flag: 10000/);
diff --git a/test/parallel/test-zlib-truncated.js b/test/parallel/test-zlib-truncated.js
index 38888b68be..1798a2ca97 100644
--- a/test/parallel/test-zlib-truncated.js
+++ b/test/parallel/test-zlib-truncated.js
@@ -45,5 +45,22 @@ const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el'
zlib[methods.decomp](truncated, function(err, result) {
assert(/unexpected end of file/.test(err.message));
});
+
+ const syncFlushOpt = { finishFlush: zlib.Z_SYNC_FLUSH };
+
+ // sync truncated input test, finishFlush = Z_SYNC_FLUSH
+ assert.doesNotThrow(function() {
+ const result = zlib[methods.decompSync](truncated, syncFlushOpt)
+ .toString();
+ assert.equal(result, inputString.substr(0, result.length));
+ });
+
+ // async truncated input test, finishFlush = Z_SYNC_FLUSH
+ zlib[methods.decomp](truncated, syncFlushOpt, function(err, decompressed) {
+ assert.ifError(err);
+
+ const result = decompressed.toString();
+ assert.equal(result, inputString.substr(0, result.length));
+ });
});
});