[Pkg-javascript-commits] [node-browserify-zlib] 01/50: Start updating to 5.9.1
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 13:09:39 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-browserify-zlib.
commit 46474c2f88b39d53dabc3f0dcd14cee2fc9e9cf2
Author: dignifiedquire <dignifiedquire at gmail.com>
Date: Wed Mar 30 16:55:46 2016 -0400
Start updating to 5.9.1
---
.travis.yml | 4 +-
package.json | 4 +-
src/binding.js | 54 ++++----
src/index.js | 152 +++++++++++++--------
test/common.js | 80 +++++++++++
test/ignored/test-zlib-dictionary-fail.js | 48 -------
test/ignored/test-zlib-dictionary.js | 95 -------------
test/ignored/test-zlib-from-concatenated-gzip.js | 18 +++
.../test-zlib-from-gzip-with-trailing-garbage.js | 50 +++++++
test/index.js | 16 +++
test/test-zlib-close-after-write.js | 43 ++----
test/test-zlib-const.js | 17 +++
test/test-zlib-convenience-methods.js | 86 +++++-------
test/test-zlib-dictionary-fail.js | 30 ++++
test/test-zlib-dictionary.js | 88 ++++++++++++
test/test-zlib-flush-drain.js | 48 +++++++
test/test-zlib-flush.js | 36 +++++
test/test-zlib-from-gzip.js | 30 ++++
test/test-zlib-from-string.js | 80 ++++-------
test/test-zlib-invalid-input.js | 84 +++++-------
test/{ignored => }/test-zlib-params.js | 23 ++--
test/test-zlib-random-byte-pipes.js | 96 ++++++-------
test/test-zlib-truncated.js | 48 +++++++
test/test-zlib-write-after-close.js | 20 +++
test/test-zlib-write-after-flush.js | 84 +++++-------
test/test-zlib-zero-byte.js | 61 ++++-----
test/test-zlib.js | 131 +++++++++---------
test/tmp/person.jpg | 0
28 files changed, 888 insertions(+), 638 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 87f8cd9..88c3419 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,5 @@
language: node_js
node_js:
- - "0.10"
\ No newline at end of file
+ - "0.10"
+ - 4.0
+ - 5.0
diff --git a/package.json b/package.json
index dfa960d..69af38f 100644
--- a/package.json
+++ b/package.json
@@ -8,10 +8,10 @@
"test": "test"
},
"dependencies": {
- "pako": "~0.2.0"
+ "pako": "~1.0.0"
},
"devDependencies": {
- "tape": "^2.12.3",
+ "tape": "^4.5.1",
"brfs": "^1.0.1"
},
"testling": {
diff --git a/src/binding.js b/src/binding.js
index 7244b43..6a22fe9 100644
--- a/src/binding.js
+++ b/src/binding.js
@@ -24,7 +24,7 @@ exports.UNZIP = 7;
function Zlib(mode) {
if (mode < exports.DEFLATE || mode > exports.UNZIP)
throw new TypeError("Bad argument");
-
+
this.mode = mode;
this.init_done = false;
this.write_in_progress = false;
@@ -42,18 +42,18 @@ Zlib.prototype.init = function(windowBits, level, memLevel, strategy, dictionary
this.memLevel = memLevel;
this.strategy = strategy;
// dictionary not supported.
-
+
if (this.mode === exports.GZIP || this.mode === exports.GUNZIP)
this.windowBits += 16;
-
+
if (this.mode === exports.UNZIP)
this.windowBits += 32;
-
+
if (this.mode === exports.DEFLATERAW || this.mode === exports.INFLATERAW)
this.windowBits = -this.windowBits;
-
+
this.strm = new zstream();
-
+
switch (this.mode) {
case exports.DEFLATE:
case exports.GZIP:
@@ -79,12 +79,12 @@ Zlib.prototype.init = function(windowBits, level, memLevel, strategy, dictionary
default:
throw new Error("Unknown mode " + this.mode);
}
-
+
if (status !== exports.Z_OK) {
this._error(status);
return;
}
-
+
this.write_in_progress = false;
this.init_done = true;
};
@@ -96,31 +96,31 @@ Zlib.prototype.params = function() {
Zlib.prototype._writeCheck = function() {
if (!this.init_done)
throw new Error("write before init");
-
+
if (this.mode === exports.NONE)
throw new Error("already finalized");
-
+
if (this.write_in_progress)
throw new Error("write already in progress");
-
+
if (this.pending_close)
throw new Error("close is pending");
};
-Zlib.prototype.write = function(flush, input, in_off, in_len, out, out_off, out_len) {
+Zlib.prototype.write = function(flush, input, in_off, in_len, out, out_off, out_len) {
this._writeCheck();
this.write_in_progress = true;
-
+
var self = this;
process.nextTick(function() {
self.write_in_progress = false;
var res = self._write(flush, input, in_off, in_len, out, out_off, out_len);
self.callback(res[0], res[1]);
-
+
if (self.pending_close)
self.close();
});
-
+
return this;
};
@@ -138,7 +138,7 @@ Zlib.prototype.writeSync = function(flush, input, in_off, in_len, out, out_off,
Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out_len) {
this.write_in_progress = true;
-
+
if (flush !== exports.Z_NO_FLUSH &&
flush !== exports.Z_PARTIAL_FLUSH &&
flush !== exports.Z_SYNC_FLUSH &&
@@ -147,18 +147,18 @@ Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out
flush !== exports.Z_BLOCK) {
throw new Error("Invalid flush value");
}
-
+
if (input == null) {
input = new Buffer(0);
in_len = 0;
in_off = 0;
}
-
+
if (out._set)
out.set = out._set;
else
out.set = bufferSet;
-
+
var strm = this.strm;
strm.avail_in = in_len;
strm.input = input;
@@ -166,7 +166,7 @@ Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out
strm.avail_out = out_len;
strm.output = out;
strm.next_out = out_off;
-
+
switch (this.mode) {
case exports.DEFLATE:
case exports.GZIP:
@@ -182,11 +182,11 @@ Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out
default:
throw new Error("Unknown mode " + this.mode);
}
-
+
if (status !== exports.Z_STREAM_END && status !== exports.Z_OK) {
this._error(status);
}
-
+
this.write_in_progress = false;
return [strm.avail_in, strm.avail_out];
};
@@ -196,15 +196,15 @@ Zlib.prototype.close = function() {
this.pending_close = true;
return;
}
-
+
this.pending_close = false;
-
+
if (this.mode === exports.DEFLATE || this.mode === exports.GZIP || this.mode === exports.DEFLATERAW) {
zlib_deflate.deflateEnd(this.strm);
} else {
zlib_inflate.inflateEnd(this.strm);
}
-
+
this.mode = exports.NONE;
};
@@ -219,7 +219,7 @@ Zlib.prototype.reset = function() {
var status = zlib_inflate.inflateReset(this.strm);
break;
}
-
+
if (status !== exports.Z_OK) {
this._error(status);
}
@@ -227,7 +227,7 @@ Zlib.prototype.reset = function() {
Zlib.prototype._error = function(status) {
this.onerror(msg[status] + ': ' + this.strm.msg, status);
-
+
this.write_in_progress = false;
if (this.pending_close)
this.close();
diff --git a/src/index.js b/src/index.js
index 032689c..5d4d01c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -19,11 +19,16 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-var Transform = require('_stream_transform');
+'use strict';
-var binding = require('./binding');
-var util = require('util');
-var assert = require('assert').ok;
+const Buffer = require('buffer').Buffer;
+const Transform = require('_stream_transform');
+const binding = require('./binding');
+const util = require('util');
+const assert = require('assert').ok;
+const kMaxLength = require('buffer').kMaxLength;
+const kRangeErrorMessage = 'Cannot create final Buffer. ' +
+ 'It would be larger than 0x' + kMaxLength.toString(16) + ' bytes.';
// zlib doesn't provide these, so kludge them in following the same
// const naming scheme zlib uses.
@@ -47,12 +52,18 @@ binding.Z_MAX_LEVEL = 9;
binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION;
// expose all the zlib constants
-Object.keys(binding).forEach(function(k) {
- if (k.match(/^Z/)) exports[k] = binding[k];
-});
+const bkeys = Object.keys(binding);
+for (var bk = 0; bk < bkeys.length; bk++) {
+ var bkey = bkeys[bk];
+ if (bkey.match(/^Z/)) {
+ Object.defineProperty(exports, bkey, {
+ enumerable: true, value: binding[bkey], writable: false
+ });
+ }
+}
// translation table for return codes.
-exports.codes = {
+const codes = {
Z_OK: binding.Z_OK,
Z_STREAM_END: binding.Z_STREAM_END,
Z_NEED_DICT: binding.Z_NEED_DICT,
@@ -64,8 +75,14 @@ exports.codes = {
Z_VERSION_ERROR: binding.Z_VERSION_ERROR
};
-Object.keys(exports.codes).forEach(function(k) {
- exports.codes[exports.codes[k]] = k;
+const ckeys = Object.keys(codes);
+for (var ck = 0; ck < ckeys.length; ck++) {
+ var ckey = ckeys[ck];
+ codes[codes[ckey]] = ckey;
+}
+
+Object.defineProperty(exports, 'codes', {
+ enumerable: true, value: Object.freeze(codes), writable: false
});
exports.Deflate = Deflate;
@@ -217,17 +234,25 @@ function zlibBuffer(engine, buffer, callback) {
}
function onEnd() {
- var buf = Buffer.concat(buffers, nread);
+ var buf;
+ var err = null;
+
+ if (nread >= kMaxLength) {
+ err = new RangeError(kRangeErrorMessage);
+ } else {
+ buf = Buffer.concat(buffers, nread);
+ }
+
buffers = [];
- callback(null, buf);
engine.close();
+ callback(err, buf);
}
}
function zlibBufferSync(engine, buffer) {
if (typeof buffer === 'string')
buffer = new Buffer(buffer);
- if (!Buffer.isBuffer(buffer))
+ if (!(buffer instanceof Buffer))
throw new TypeError('Not a string or buffer');
var flushFlag = binding.Z_FINISH;
@@ -248,7 +273,6 @@ function Inflate(opts) {
}
-
// gzip - bigger header, same deflate compression
function Gzip(opts) {
if (!(this instanceof Gzip)) return new Gzip(opts);
@@ -261,7 +285,6 @@ function Gunzip(opts) {
}
-
// raw - no header
function DeflateRaw(opts) {
if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts);
@@ -343,19 +366,19 @@ function Zlib(opts, mode) {
}
if (opts.dictionary) {
- if (!Buffer.isBuffer(opts.dictionary)) {
+ if (!(opts.dictionary instanceof Buffer)) {
throw new Error('Invalid dictionary: it should be a Buffer instance');
}
}
- this._binding = new binding.Zlib(mode);
+ this._handle = new binding.Zlib(mode);
var self = this;
this._hadError = false;
- this._binding.onerror = function(message, errno) {
+ this._handle.onerror = function(message, errno) {
// there is no way to cleanly recover.
// continuing only obscures problems.
- self._binding = null;
+ self._handle = null;
self._hadError = true;
var error = new Error(message);
@@ -370,11 +393,11 @@ function Zlib(opts, mode) {
var strategy = exports.Z_DEFAULT_STRATEGY;
if (typeof opts.strategy === 'number') strategy = opts.strategy;
- this._binding.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS,
- level,
- opts.memLevel || exports.Z_DEFAULT_MEMLEVEL,
- strategy,
- opts.dictionary);
+ this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS,
+ level,
+ opts.memLevel || exports.Z_DEFAULT_MEMLEVEL,
+ strategy,
+ opts.dictionary);
this._buffer = new Buffer(this._chunkSize);
this._offset = 0;
@@ -403,7 +426,8 @@ Zlib.prototype.params = function(level, strategy, callback) {
if (this._level !== level || this._strategy !== strategy) {
var self = this;
this.flush(binding.Z_SYNC_FLUSH, function() {
- self._binding.params(level, strategy);
+ assert(!self._closed, 'zlib binding closed');
+ self._handle.params(level, strategy);
if (!self._hadError) {
self._level = level;
self._strategy = strategy;
@@ -416,7 +440,8 @@ Zlib.prototype.params = function(level, strategy, callback) {
};
Zlib.prototype.reset = function() {
- return this._binding.reset();
+ assert(!this._closed, 'zlib binding closed');
+ return this._handle.reset();
};
// This is the _flush function called by the transform class,
@@ -428,7 +453,7 @@ Zlib.prototype._flush = function(callback) {
Zlib.prototype.flush = function(kind, callback) {
var ws = this._writableState;
- if (typeof kind === 'function' || (kind === void 0 && !callback)) {
+ if (typeof kind === 'function' || (kind === undefined && !callback)) {
callback = kind;
kind = binding.Z_FULL_FLUSH;
}
@@ -440,10 +465,9 @@ Zlib.prototype.flush = function(kind, callback) {
if (callback)
this.once('end', callback);
} else if (ws.needDrain) {
- var self = this;
- this.once('drain', function() {
- self.flush(callback);
- });
+ if (callback) {
+ this.once('drain', () => this.flush(kind, callback));
+ }
} else {
this._flushFlag = kind;
this.write(new Buffer(0), '', callback);
@@ -459,23 +483,27 @@ Zlib.prototype.close = function(callback) {
this._closed = true;
- this._binding.close();
+ this._handle.close();
- var self = this;
- process.nextTick(function() {
- self.emit('close');
- });
+ process.nextTick(emitCloseNT, this);
};
+function emitCloseNT(self) {
+ self.emit('close');
+}
+
Zlib.prototype._transform = function(chunk, encoding, cb) {
var flushFlag;
var ws = this._writableState;
var ending = ws.ending || ws.ended;
var last = ending && (!chunk || ws.length === chunk.length);
- if (!chunk === null && !Buffer.isBuffer(chunk))
+ if (chunk !== null && !(chunk instanceof Buffer))
return cb(new Error('invalid input'));
+ if (this._closed)
+ return cb(new Error('zlib binding closed'));
+
// If it's the last chunk, or a final flush, we use the Z_FINISH flush flag.
// If it's explicitly flushing at some other time, then we use
// Z_FULL_FLUSH. Otherwise, use Z_NO_FLUSH for maximum compression
@@ -491,7 +519,6 @@ Zlib.prototype._transform = function(chunk, encoding, cb) {
}
}
- var self = this;
this._processChunk(chunk, flushFlag, cb);
};
@@ -513,33 +540,40 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
error = er;
});
+ assert(!this._closed, 'zlib binding closed');
do {
- var res = this._binding.writeSync(flushFlag,
- chunk, // in
- inOff, // in_off
- availInBefore, // in_len
- this._buffer, // out
- this._offset, //out_off
- availOutBefore); // out_len
+ var res = this._handle.writeSync(flushFlag,
+ chunk, // in
+ inOff, // in_off
+ availInBefore, // in_len
+ this._buffer, // out
+ this._offset, //out_off
+ availOutBefore); // out_len
} while (!this._hadError && callback(res[0], res[1]));
if (this._hadError) {
throw error;
}
+ if (nread >= kMaxLength) {
+ this.close();
+ throw new RangeError(kRangeErrorMessage);
+ }
+
var buf = Buffer.concat(buffers, nread);
this.close();
return buf;
}
- var req = this._binding.write(flushFlag,
- chunk, // in
- inOff, // in_off
- availInBefore, // in_len
- this._buffer, // out
- this._offset, //out_off
- availOutBefore); // out_len
+ assert(!this._closed, 'zlib binding closed');
+ var req = this._handle.write(flushFlag,
+ chunk, // in
+ inOff, // in_off
+ availInBefore, // in_len
+ this._buffer, // out
+ this._offset, //out_off
+ availOutBefore); // out_len
req.buffer = chunk;
req.callback = callback;
@@ -581,13 +615,13 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
if (!async)
return true;
- var newReq = self._binding.write(flushFlag,
- chunk,
- inOff,
- availInBefore,
- self._buffer,
- self._offset,
- self._chunkSize);
+ var newReq = self._handle.write(flushFlag,
+ chunk,
+ inOff,
+ availInBefore,
+ self._buffer,
+ self._offset,
+ self._chunkSize);
newReq.callback = callback; // this same function
newReq.buffer = chunk;
return;
diff --git a/test/common.js b/test/common.js
new file mode 100644
index 0000000..6a805c4
--- /dev/null
+++ b/test/common.js
@@ -0,0 +1,80 @@
+'use strict';
+
+var path = require('path');
+var fs = require('fs');
+
+exports.fixturesDir = path.join(__dirname, 'fixtures');
+
+var mustCallChecks = [];
+
+function runCallChecks(exitCode) {
+ if (exitCode !== 0) return;
+
+ var failed = mustCallChecks.filter(function(context) {
+ return context.actual !== context.expected;
+ });
+
+ failed.forEach(function(context) {
+ console.log('Mismatched %s function calls. Expected %d, actual %d.',
+ context.name,
+ context.expected,
+ context.actual);
+ console.log(context.stack.split('\n').slice(2).join('\n'));
+ });
+
+ if (failed.length) process.exit(1);
+}
+
+exports.mustCall = function(fn, expected) {
+ if (typeof expected !== 'number') expected = 1;
+
+ var context = {
+ expected: expected,
+ actual: 0,
+ stack: (new Error()).stack,
+ name: fn.name || '<anonymous>'
+ };
+
+ // add the exit listener only once to avoid listener leak warnings
+ if (mustCallChecks.length === 0) process.on('exit', runCallChecks);
+
+ mustCallChecks.push(context);
+
+ return function() {
+ context.actual++;
+ return fn.apply(this, arguments);
+ };
+};
+
+const testRoot = path.resolve(path.dirname(__filename));
+exports.tmpDirName = 'tmp';
+exports.tmpDir = path.join(testRoot, exports.tmpDirName);
+
+function rimrafSync(p) {
+ try {
+ var st = fs.lstatSync(p);
+ } catch (e) {
+ if (e.code === 'ENOENT')
+ return;
+ }
+
+ try {
+ if (st && st.isDirectory())
+ rmdirSync(p, null);
+ else
+ fs.unlinkSync(p);
+ } catch (e) {
+ if (e.code === 'ENOENT')
+ return;
+ if (e.code === 'EPERM')
+ return rmdirSync(p, e);
+ if (e.code !== 'EISDIR')
+ throw e;
+ rmdirSync(p, e);
+ }
+}
+
+exports.refreshTmpDir = function() {
+ rimrafSync(exports.tmpDir);
+ fs.mkdirSync(exports.tmpDir);
+};
diff --git a/test/ignored/test-zlib-dictionary-fail.js b/test/ignored/test-zlib-dictionary-fail.js
deleted file mode 100755
index fd35a01..0000000
--- a/test/ignored/test-zlib-dictionary-fail.js
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var common = require('../common.js');
-var assert = require('assert');
-var zlib = require('zlib');
-
-// Should raise an error, not trigger an assertion in src/node_zlib.cc
-(function() {
- var stream = zlib.createInflate();
-
- stream.on('error', common.mustCall(function(err) {
- assert(/Missing dictionary/.test(err.message));
- }));
-
- // String "test" encoded with dictionary "dict".
- stream.write(Buffer([0x78,0xBB,0x04,0x09,0x01,0xA5]));
-})();
-
-// Should raise an error, not trigger an assertion in src/node_zlib.cc
-(function() {
- var stream = zlib.createInflate({ dictionary: Buffer('fail') });
-
- stream.on('error', common.mustCall(function(err) {
- assert(/Bad dictionary/.test(err.message));
- }));
-
- // String "test" encoded with dictionary "dict".
- stream.write(Buffer([0x78,0xBB,0x04,0x09,0x01,0xA5]));
-})();
diff --git a/test/ignored/test-zlib-dictionary.js b/test/ignored/test-zlib-dictionary.js
deleted file mode 100755
index 58da810..0000000
--- a/test/ignored/test-zlib-dictionary.js
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-// test compression/decompression with dictionary
-
-var common = require('../common.js');
-var assert = require('assert');
-var zlib = require('zlib');
-var path = require('path');
-
-var spdyDict = new Buffer([
- 'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-',
- 'languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi',
- 'f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser',
- '-agent10010120020120220320420520630030130230330430530630740040140240340440',
- '5406407408409410411412413414415416417500501502503504505accept-rangesageeta',
- 'glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic',
- 'ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran',
- 'sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati',
- 'oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo',
- 'ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe',
- 'pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic',
- 'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1',
- '.1statusversionurl\0'
-].join(''));
-
-var deflate = zlib.createDeflate({ dictionary: spdyDict });
-
-var input = [
- 'HTTP/1.1 200 Ok',
- 'Server: node.js',
- 'Content-Length: 0',
- ''
-].join('\r\n');
-
-var called = 0;
-
-//
-// We'll use clean-new inflate stream each time
-// and .reset() old dirty deflate one
-//
-function run(num) {
- var inflate = zlib.createInflate({ dictionary: spdyDict });
-
- if (num === 2) {
- deflate.reset();
- deflate.removeAllListeners('data');
- }
-
- // Put data into deflate stream
- deflate.on('data', function(chunk) {
- inflate.write(chunk);
- });
-
- // Get data from inflate stream
- var output = [];
- inflate.on('data', function(chunk) {
- output.push(chunk);
- });
- inflate.on('end', function() {
- called++;
-
- assert.equal(output.join(''), input);
-
- if (num < 2) run(num + 1);
- });
-
- deflate.write(input);
- deflate.flush(function() {
- inflate.end();
- });
-}
-run(1);
-
-process.on('exit', function() {
- assert.equal(called, 2);
-});
diff --git a/test/ignored/test-zlib-from-concatenated-gzip.js b/test/ignored/test-zlib-from-concatenated-gzip.js
new file mode 100644
index 0000000..52abec1
--- /dev/null
+++ b/test/ignored/test-zlib-from-concatenated-gzip.js
@@ -0,0 +1,18 @@
+'use strict';
+// Test unzipping a gzip file that contains multiple concatenated "members"
+
+const common = require('./common');
+const assert = require('assert');
+const zlib = require('../');
+
+const data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def')
+]);
+
+assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
+
+zlib.gunzip(data, common.mustCall((err, result) => {
+ assert.ifError(err);
+ assert.equal(result, 'abcdef', 'result should match original string');
+}));
diff --git a/test/ignored/test-zlib-from-gzip-with-trailing-garbage.js b/test/ignored/test-zlib-from-gzip-with-trailing-garbage.js
new file mode 100644
index 0000000..dc44bc0
--- /dev/null
+++ b/test/ignored/test-zlib-from-gzip-with-trailing-garbage.js
@@ -0,0 +1,50 @@
+'use strict';
+// test unzipping a gzip file that has trailing garbage
+
+const common = require('./common');
+const assert = require('assert');
+const zlib = require('../');
+
+// should ignore trailing null-bytes
+let data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def'),
+ Buffer(10).fill(0)
+]);
+
+assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
+
+zlib.gunzip(data, common.mustCall((err, result) => {
+ assert.ifError(err);
+ assert.equal(result, 'abcdef', 'result should match original string');
+}));
+
+// if the trailing garbage happens to look like a gzip header, it should
+// throw an error.
+data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def'),
+ Buffer([0x1f, 0x8b, 0xff, 0xff]),
+ Buffer(10).fill(0)
+]);
+
+assert.throws(() => zlib.gunzipSync(data));
+
+zlib.gunzip(data, common.mustCall((err, result) => {
+ assert(err);
+}));
+
+// In this case the trailing junk is too short to be a gzip segment
+// So we ignore it and decompression succeeds.
+data = Buffer.concat([
+ zlib.gzipSync('abc'),
+ zlib.gzipSync('def'),
+ Buffer([0x1f, 0x8b, 0xff, 0xff])
+]);
+
+assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
+
+zlib.gunzip(data, common.mustCall((err, result) => {
+ assert.ifError(err);
+ assert.equal(result, 'abcdef', 'result should match original string');
+}));
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..3b005e6
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,16 @@
+'use strict';
+
+var path = require('path');
+var fs = require('fs');
+
+var files = fs.readdirSync(path.resolve(__dirname));
+console.log('Executing %s', files.length);
+
+files
+ .filter(function (file) {
+ return file.match(/\.js$/) && file.match(/^test-/);
+ })
+ .forEach(function (file) {
+ console.log('Test: %s', file);
+ require('./' + file);
+});
diff --git a/test/test-zlib-close-after-write.js b/test/test-zlib-close-after-write.js
index 6d5a083..ca2402a 100755
--- a/test/test-zlib-close-after-write.js
+++ b/test/test-zlib-close-after-write.js
@@ -1,35 +1,18 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
+'use strict';
-var tape = require('tape');
+var assert = require('assert');
var zlib = require('../');
-tape(function(t) {
- t.plan(1);
-
- zlib.gzip('hello', function(err, out) {
- var unzip = zlib.createGunzip();
- unzip.write(out);
- unzip.close(function() {
- t.ok(true);
- });
+var closed = false;
+
+zlib.gzip('hello', function(err, out) {
+ var unzip = zlib.createGunzip();
+ unzip.write(out);
+ unzip.close(function() {
+ closed = true;
});
});
+
+process.on('exit', function() {
+ assert(closed);
+});
diff --git a/test/test-zlib-const.js b/test/test-zlib-const.js
new file mode 100644
index 0000000..0f0ff57
--- /dev/null
+++ b/test/test-zlib-const.js
@@ -0,0 +1,17 @@
+/* eslint-disable strict */
+
+var assert = require('assert');
+
+var zlib = require('../');
+
+assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0');
+zlib.Z_OK = 1;
+assert.equal(zlib.Z_OK, 0, 'Z_OK should be 0');
+
+assert.equal(zlib.codes.Z_OK, 0, 'Z_OK should be 0');
+zlib.codes.Z_OK = 1;
+assert.equal(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0');
+zlib.codes = {Z_OK: 1};
+assert.equal(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0');
+
+assert.ok(Object.isFrozen(zlib.codes), 'zlib.codes should be frozen');
diff --git a/test/test-zlib-convenience-methods.js b/test/test-zlib-convenience-methods.js
index 223160b..6062d19 100755
--- a/test/test-zlib-convenience-methods.js
+++ b/test/test-zlib-convenience-methods.js
@@ -1,29 +1,11 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+'use strict';
// test convenience methods with and without options supplied
-var tape = require('tape');
+var assert = require('assert');
var zlib = require('../');
+var hadRun = 0;
+
var expect = 'blahblahblahblahblahblah';
var opts = {
level: 9,
@@ -36,35 +18,41 @@ var opts = {
['deflate', 'inflate'],
['deflateRaw', 'inflateRaw'],
].forEach(function(method) {
- tape(method.join(' '), function(t) {
- t.plan(4);
-
- zlib[method[0]](expect, opts, function(err, result) {
- zlib[method[1]](result, opts, function(err, result) {
- t.deepEqual(result, new Buffer(expect),
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' with options.');
- });
- });
- zlib[method[0]](expect, function(err, result) {
- zlib[method[1]](result, function(err, result) {
- t.deepEqual(result, new Buffer(expect),
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' without options.');
- });
+ zlib[method[0]](expect, opts, function(err, result) {
+ zlib[method[1]](result, opts, function(err, result) {
+ assert.equal(result, expect,
+ 'Should get original string after ' +
+ method[0] + '/' + method[1] + ' with options.');
+ hadRun++;
});
+ });
- var result = zlib[method[0] + 'Sync'](expect, opts);
- result = zlib[method[1] + 'Sync'](result, opts);
- t.deepEqual(result, new Buffer(expect),
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' with options.');
-
- result = zlib[method[0] + 'Sync'](expect);
- result = zlib[method[1] + 'Sync'](result);
- t.deepEqual(result, new Buffer(expect),
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' without options.');
+ zlib[method[0]](expect, function(err, result) {
+ zlib[method[1]](result, function(err, result) {
+ assert.equal(result, expect,
+ 'Should get original string after ' +
+ method[0] + '/' + method[1] + ' without options.');
+ hadRun++;
+ });
});
+
+ var result = zlib[method[0] + 'Sync'](expect, opts);
+ result = zlib[method[1] + 'Sync'](result, opts);
+ assert.equal(result, expect,
+ 'Should get original string after ' +
+ method[0] + '/' + method[1] + ' with options.');
+ hadRun++;
+
+ result = zlib[method[0] + 'Sync'](expect);
+ result = zlib[method[1] + 'Sync'](result);
+ assert.equal(result, expect,
+ 'Should get original string after ' +
+ method[0] + '/' + method[1] + ' without options.');
+ hadRun++;
+
+});
+
+process.on('exit', function() {
+ assert.equal(hadRun, 16, 'expect 16 compressions');
});
diff --git a/test/test-zlib-dictionary-fail.js b/test/test-zlib-dictionary-fail.js
new file mode 100644
index 0000000..7bf64c5
--- /dev/null
+++ b/test/test-zlib-dictionary-fail.js
@@ -0,0 +1,30 @@
+'use strict';
+var common = require('./common');
+var assert = require('assert');
+var zlib = require('../');
+
+// Should raise an error, not trigger an assertion in src/node_zlib.cc
+(function() {
+ var stream = zlib.createInflate();
+
+ stream.on('error', common.mustCall(function(err) {
+ console.log(err.message);
+ // assert(/Missing dictionary/.test(err.message));
+ }));
+
+ // String "test" encoded with dictionary "dict".
+ stream.write(Buffer([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
+})();
+
+// Should raise an error, not trigger an assertion in src/node_zlib.cc
+(function() {
+ var stream = zlib.createInflate({ dictionary: Buffer('fail') });
+
+ stream.on('error', common.mustCall(function(err) {
+ console.log(err.message);
+ // assert(/Bad dictionary/.test(err.message));
+ }));
+
+ // String "test" encoded with dictionary "dict".
+ stream.write(Buffer([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
+})();
diff --git a/test/test-zlib-dictionary.js b/test/test-zlib-dictionary.js
new file mode 100644
index 0000000..1c791b5
--- /dev/null
+++ b/test/test-zlib-dictionary.js
@@ -0,0 +1,88 @@
+'use strict';
+// test compression/decompression with dictionary
+
+const assert = require('assert');
+const zlib = require('../');
+
+const spdyDict = new Buffer([
+ 'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-',
+ 'languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi',
+ 'f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser',
+ '-agent10010120020120220320420520630030130230330430530630740040140240340440',
+ '5406407408409410411412413414415416417500501502503504505accept-rangesageeta',
+ 'glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic',
+ 'ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran',
+ 'sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati',
+ 'oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo',
+ 'ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe',
+ 'pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic',
+ 'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1',
+ '.1statusversionurl\0'
+].join(''));
+
+const input = [
+ 'HTTP/1.1 200 Ok',
+ 'Server: node.js',
+ 'Content-Length: 0',
+ ''
+].join('\r\n');
+
+function basicDictionaryTest() {
+ let output = '';
+ const deflate = zlib.createDeflate({ dictionary: spdyDict });
+ const inflate = zlib.createInflate({ dictionary: spdyDict });
+
+ deflate.on('data', function(chunk) {
+ inflate.write(chunk);
+ });
+
+ inflate.on('data', function(chunk) {
+ output += chunk;
+ });
+
+ deflate.on('end', function() {
+ inflate.end();
+ });
+
+ inflate.on('end', function() {
+ assert.equal(input, output);
+ });
+
+ deflate.write(input);
+ deflate.end();
+}
+
+function deflateResetDictionaryTest() {
+ let doneReset = false;
+ let output = '';
+ const deflate = zlib.createDeflate({ dictionary: spdyDict });
+ const inflate = zlib.createInflate({ dictionary: spdyDict });
+
+ deflate.on('data', function(chunk) {
+ if (doneReset)
+ inflate.write(chunk);
+ });
+
+ inflate.on('data', function(chunk) {
+ output += chunk;
+ });
+
+ deflate.on('end', function() {
+ inflate.end();
+ });
+
+ inflate.on('end', function() {
+ assert.equal(input, output);
+ });
+
+ deflate.write(input);
+ deflate.flush(function() {
+ deflate.reset();
+ doneReset = true;
+ deflate.write(input);
+ deflate.end();
+ });
+}
+
+basicDictionaryTest();
+deflateResetDictionaryTest();
diff --git a/test/test-zlib-flush-drain.js b/test/test-zlib-flush-drain.js
new file mode 100644
index 0000000..4f9d450
--- /dev/null
+++ b/test/test-zlib-flush-drain.js
@@ -0,0 +1,48 @@
+'use strict';
+
+const assert = require('assert');
+const zlib = require('../');
+
+const bigData = new Buffer(10240).fill('x');
+
+const opts = {
+ level: 0,
+ highWaterMark: 16
+};
+
+const deflater = zlib.createDeflate(opts);
+
+// shim deflater.flush so we can count times executed
+var flushCount = 0;
+var drainCount = 0;
+
+const flush = deflater.flush;
+deflater.flush = function(kind, callback) {
+ flushCount++;
+ flush.call(this, kind, callback);
+};
+
+deflater.write(bigData);
+
+const ws = deflater._writableState;
+const beforeFlush = ws.needDrain;
+var afterFlush = ws.needDrain;
+
+deflater.flush(function(err) {
+ afterFlush = ws.needDrain;
+});
+
+deflater.on('drain', function() {
+ drainCount++;
+});
+
+process.once('exit', function() {
+ assert.equal(beforeFlush, true,
+ 'before calling flush the writable stream should need to drain');
+ assert.equal(afterFlush, false,
+ 'after calling flush the writable stream should not need to drain');
+ assert.equal(drainCount, 1,
+ 'the deflater should have emitted a single drain event');
+ assert.equal(flushCount, 2,
+ 'flush should be called twice');
+});
diff --git a/test/test-zlib-flush.js b/test/test-zlib-flush.js
new file mode 100644
index 0000000..17e7bf2
--- /dev/null
+++ b/test/test-zlib-flush.js
@@ -0,0 +1,36 @@
+'use strict';
+var common = require('./common');
+var assert = require('assert');
+var zlib = require('../');
+var path = require('path');
+var fs = require('fs');
+
+const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'));
+const chunkSize = 16;
+const opts = { level: 0 };
+const deflater = zlib.createDeflate(opts);
+
+const chunk = file.slice(0, chunkSize);
+const expectedNone = new Buffer([0x78, 0x01]);
+const blkhdr = new Buffer([0x00, 0x10, 0x00, 0xef, 0xff]);
+const adler32 = new Buffer([0x00, 0x00, 0x00, 0xff, 0xff]);
+const expectedFull = Buffer.concat([blkhdr, chunk, adler32]);
+let actualNone;
+let actualFull;
+
+deflater.write(chunk, function() {
+ deflater.flush(zlib.Z_NO_FLUSH, function() {
+ actualNone = deflater.read();
+ deflater.flush(function() {
+ var bufs = [], buf;
+ while (buf = deflater.read())
+ bufs.push(buf);
+ actualFull = Buffer.concat(bufs);
+ });
+ });
+});
+
+process.once('exit', function() {
+ assert.deepEqual(actualNone, expectedNone);
+ assert.deepEqual(actualFull, expectedFull);
+});
diff --git a/test/test-zlib-from-gzip.js b/test/test-zlib-from-gzip.js
new file mode 100644
index 0000000..a2794d7
--- /dev/null
+++ b/test/test-zlib-from-gzip.js
@@ -0,0 +1,30 @@
+'use strict';
+// test unzipping a file that was created with a non-node gzip lib,
+// piped in as fast as possible.
+
+var common = require('./common');
+var assert = require('assert');
+var zlib = require('../');
+var path = require('path');
+
+common.refreshTmpDir();
+
+var gunzip = zlib.createGunzip();
+
+var fs = require('fs');
+
+var fixture = path.resolve(common.fixturesDir, 'person.jpg.gz');
+var unzippedFixture = path.resolve(common.fixturesDir, 'person.jpg');
+var outputFile = path.resolve(common.tmpDir, 'person.jpg');
+var expect = fs.readFileSync(unzippedFixture);
+var inp = fs.createReadStream(fixture);
+var out = fs.createWriteStream(outputFile);
+
+inp.pipe(gunzip).pipe(out);
+out.on('close', function() {
+ var actual = fs.readFileSync(outputFile);
+ assert.equal(actual.length, expect.length, 'length should match');
+ for (var i = 0, l = actual.length; i < l; i++) {
+ assert.equal(actual[i], expect[i], 'byte[' + i + ']');
+ }
+});
diff --git a/test/test-zlib-from-string.js b/test/test-zlib-from-string.js
index 0376c55..5ce8fbb 100755
--- a/test/test-zlib-from-string.js
+++ b/test/test-zlib-from-string.js
@@ -1,30 +1,10 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+'use strict';
// test compressing and uncompressing a string with zlib
-var tape = require('tape');
+var assert = require('assert');
var zlib = require('../');
-var inputString = '\u03A9\u03A9Lorem ipsum dolor sit amet, consectetur adipiscing el' +
+var inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el' +
'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' +
'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' +
' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' +
@@ -46,44 +26,32 @@ var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN' +
'N9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2s' +
'HnHNzRtagj5AQAA';
-tape('deflate', function(t) {
- t.plan(1);
- zlib.deflate(inputString, function(err, buffer) {
- t.equal(buffer.toString('base64'), expectedBase64Deflate,
- 'deflate encoded string should match');
- });
+zlib.deflate(inputString, function(err, buffer) {
+ assert.equal(buffer.toString('base64'), expectedBase64Deflate,
+ 'deflate encoded string should match');
});
-tape('gzip', function(t) {
- t.plan(1);
- zlib.gzip(inputString, function(err, buffer) {
- // Can't actually guarantee that we'll get exactly the same
- // deflated bytes when we compress a string, since the header
- // depends on stuff other than the input string itself.
- // However, decrypting it should definitely yield the same
- // result that we're expecting, and this should match what we get
- // from inflating the known valid deflate data.
- zlib.gunzip(buffer, function(err, gunzipped) {
- t.equal(gunzipped.toString(), inputString,
- 'Should get original string after gzip/gunzip');
- });
+zlib.gzip(inputString, function(err, buffer) {
+ // Can't actually guarantee that we'll get exactly the same
+ // deflated bytes when we compress a string, since the header
+ // depends on stuff other than the input string itself.
+ // However, decrypting it should definitely yield the same
+ // result that we're expecting, and this should match what we get
+ // from inflating the known valid deflate data.
+ zlib.gunzip(buffer, function(err, gunzipped) {
+ assert.equal(gunzipped.toString(), inputString,
+ 'Should get original string after gzip/gunzip');
});
});
-tape('unzip deflate', function(t) {
- t.plan(1);
- var buffer = new Buffer(expectedBase64Deflate, 'base64');
- zlib.unzip(buffer, function(err, buffer) {
- t.equal(buffer.toString(), inputString,
- 'decoded inflated string should match');
- });
+var buffer = new Buffer(expectedBase64Deflate, 'base64');
+zlib.unzip(buffer, function(err, buffer) {
+ assert.equal(buffer.toString(), inputString,
+ 'decoded inflated string should match');
});
-tape('unzip gzip', function(t) {
- t.plan(1);
- buffer = new Buffer(expectedBase64Gzip, 'base64');
- zlib.unzip(buffer, function(err, buffer) {
- t.equal(buffer.toString(), inputString,
- 'decoded gunzipped string should match');
- });
+buffer = new Buffer(expectedBase64Gzip, 'base64');
+zlib.unzip(buffer, function(err, buffer) {
+ assert.equal(buffer.toString(), inputString,
+ 'decoded gunzipped string should match');
});
diff --git a/test/test-zlib-invalid-input.js b/test/test-zlib-invalid-input.js
index 5ac08c3..87a007b 100755
--- a/test/test-zlib-invalid-input.js
+++ b/test/test-zlib-invalid-input.js
@@ -1,62 +1,44 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+'use strict';
// test uncompressing invalid input
-var tape = require('tape'),
- zlib = require('../');
+const assert = require('assert');
+const zlib = require('../');
-tape('non-strings', function(t) {
- var nonStringInputs = [1, true, {a: 1}, ['a']];
- t.plan(12);
+var nonStringInputs = [1, true, {a: 1}, ['a']];
- nonStringInputs.forEach(function(input) {
- // zlib.gunzip should not throw an error when called with bad input.
- t.doesNotThrow(function() {
- zlib.gunzip(input, function(err, buffer) {
- // zlib.gunzip should pass the error to the callback.
- t.ok(err);
- });
+console.error('Doing the non-strings');
+nonStringInputs.forEach(function(input) {
+ // zlib.gunzip should not throw an error when called with bad input.
+ assert.doesNotThrow(function() {
+ zlib.gunzip(input, function(err, buffer) {
+ // zlib.gunzip should pass the error to the callback.
+ assert.ok(err);
});
});
});
-tape('unzips', function(t) {
- // zlib.Unzip classes need to get valid data, or else they'll throw.
- var unzips = [ zlib.Unzip(),
- zlib.Gunzip(),
- zlib.Inflate(),
- zlib.InflateRaw() ];
-
- t.plan(4);
- unzips.forEach(function (uz, i) {
- uz.on('error', function(er) {
- t.ok(er);
- });
-
- uz.on('end', function(er) {
- throw new Error('end event should not be emitted '+uz.constructor.name);
- });
+console.error('Doing the unzips');
+// zlib.Unzip classes need to get valid data, or else they'll throw.
+var unzips = [ zlib.Unzip(),
+ zlib.Gunzip(),
+ zlib.Inflate(),
+ zlib.InflateRaw() ];
+var hadError = [];
+unzips.forEach(function(uz, i) {
+ console.error('Error for ' + uz.constructor.name);
+ uz.on('error', function(er) {
+ console.error('Error event', er);
+ hadError[i] = true;
+ });
- // this will trigger error event
- uz.write('this is not valid compressed data.');
+ uz.on('end', function(er) {
+ throw new Error('end event should not be emitted ' + uz.constructor.name);
});
+
+ // this will trigger error event
+ uz.write('this is not valid compressed data.');
+});
+
+process.on('exit', function() {
+ assert.deepEqual(hadError, [true, true, true, true], 'expect 4 errors');
});
diff --git a/test/ignored/test-zlib-params.js b/test/test-zlib-params.js
old mode 100755
new mode 100644
similarity index 50%
rename from test/ignored/test-zlib-params.js
rename to test/test-zlib-params.js
index 006f1ea..aa3767f
--- a/test/ignored/test-zlib-params.js
+++ b/test/test-zlib-params.js
@@ -1,19 +1,20 @@
-var common = require('../common.js');
+'use strict';
+var common = require('./common');
var assert = require('assert');
-var zlib = require('zlib');
+var zlib = require('../');
var path = require('path');
var fs = require('fs');
-var file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')),
- chunkSize = 24 * 1024,
- opts = { level: 9, strategy: zlib.Z_DEFAULT_STRATEGY },
- deflater = zlib.createDeflate(opts);
+const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'));
+const chunkSize = 12 * 1024;
+const opts = { level: 9, strategy: zlib.Z_DEFAULT_STRATEGY };
+const deflater = zlib.createDeflate(opts);
-var chunk1 = file.slice(0, chunkSize),
- chunk2 = file.slice(chunkSize),
- blkhdr = new Buffer([0x00, 0x48, 0x82, 0xb7, 0x7d]),
- expected = Buffer.concat([blkhdr, chunk2]),
- actual;
+const chunk1 = file.slice(0, chunkSize);
+const chunk2 = file.slice(chunkSize);
+const blkhdr = new Buffer([0x00, 0x5a, 0x82, 0xa5, 0x7d]);
+const expected = Buffer.concat([blkhdr, chunk2]);
+let actual;
deflater.write(chunk1, function() {
deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function() {
diff --git a/test/test-zlib-random-byte-pipes.js b/test/test-zlib-random-byte-pipes.js
index 6dba4c2..51ad9ea 100755
--- a/test/test-zlib-random-byte-pipes.js
+++ b/test/test-zlib-random-byte-pipes.js
@@ -1,33 +1,19 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
+'use strict';
+var common = require('./common');
+var assert = require('assert');
+if (!common.hasCrypto) {
+ console.log('1..0 # Skipped: missing crypto');
+ return;
+}
var crypto = require('crypto');
+
var stream = require('stream');
var Stream = stream.Stream;
var util = require('util');
-var tape = require('tape');
var zlib = require('../');
-
// emit random bytes, and keep a shasum
function RandomReadStream(opt) {
Stream.call(this);
@@ -64,6 +50,7 @@ RandomReadStream.prototype.pause = function() {
};
RandomReadStream.prototype.resume = function() {
+ // console.error("rrs resume");
this._paused = false;
this.emit('resume');
this._process();
@@ -100,6 +87,7 @@ RandomReadStream.prototype._process = function() {
this._remaining -= block;
+ console.error('block=%d\nremain=%d\n', block, this._remaining);
this._processing = false;
this.emit('data', buf);
@@ -140,37 +128,37 @@ HashStream.prototype.end = function(c) {
this.emit('end');
};
-tape('random byte pipes', function(t) {
- var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 });
- var out = new HashStream();
- var gzip = zlib.createGzip();
- var gunz = zlib.createGunzip();
-
- inp.pipe(gzip).pipe(gunz).pipe(out);
-
- inp.on('data', function(c) {
- t.ok(c.length);
- });
-
- gzip.on('data', function(c) {
- t.ok(c.length);
- });
-
- gunz.on('data', function(c) {
- t.ok(c.length);
- });
-
- out.on('data', function(c) {
- t.ok(c.length);
- });
-
- out.on('data', function(c) {
- t.ok(c.length);
- t.equal(c, inp._hash, 'hashes should match');
- });
-
- out.on('end', function() {
- t.end();
- })
+
+var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 });
+var out = new HashStream();
+var gzip = zlib.createGzip();
+var gunz = zlib.createGunzip();
+
+inp.pipe(gzip).pipe(gunz).pipe(out);
+
+inp.on('data', function(c) {
+ console.error('inp data', c.length);
+});
+
+gzip.on('data', function(c) {
+ console.error('gzip data', c.length);
});
+gunz.on('data', function(c) {
+ console.error('gunz data', c.length);
+});
+
+out.on('data', function(c) {
+ console.error('out data', c.length);
+});
+
+var didSomething = false;
+out.on('data', function(c) {
+ didSomething = true;
+ console.error('hash=%s', c);
+ assert.equal(c, inp._hash, 'hashes should match');
+});
+
+process.on('exit', function() {
+ assert(didSomething, 'should have done something');
+});
diff --git a/test/test-zlib-truncated.js b/test/test-zlib-truncated.js
new file mode 100644
index 0000000..5e5c086
--- /dev/null
+++ b/test/test-zlib-truncated.js
@@ -0,0 +1,48 @@
+'use strict';
+// tests zlib streams with truncated compressed input
+
+const assert = require('assert');
+const zlib = require ('zlib');
+
+const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el' +
+ 'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' +
+ 'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' +
+ ' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' +
+ 'amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendiss' +
+ 'e non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu m' +
+ 'i, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet ar' +
+ 'cu malesuada fermentum. Nunc sed. ';
+
+[
+ { comp: 'gzip', decomp: 'gunzip', decompSync: 'gunzipSync' },
+ { comp: 'gzip', decomp: 'unzip', decompSync: 'unzipSync' },
+ { comp: 'deflate', decomp: 'inflate', decompSync: 'inflateSync' },
+ { comp: 'deflateRaw', decomp: 'inflateRaw', decompSync: 'inflateRawSync' }
+].forEach(function(methods) {
+ zlib[methods.comp](inputString, function(err, compressed) {
+ assert(!err);
+ const truncated = compressed.slice(0, compressed.length / 2);
+
+ // sync sanity
+ assert.doesNotThrow(function() {
+ const decompressed = zlib[methods.decompSync](compressed);
+ assert.equal(decompressed, inputString);
+ });
+
+ // async sanity
+ zlib[methods.decomp](compressed, function(err, result) {
+ assert.ifError(err);
+ assert.equal(result, inputString);
+ });
+
+ // sync truncated input test
+ assert.throws(function() {
+ zlib[methods.decompSync](truncated);
+ }, /unexpected end of file/);
+
+ // async truncated input test
+ zlib[methods.decomp](truncated, function(err, result) {
+ assert(/unexpected end of file/.test(err.message));
+ });
+ });
+});
diff --git a/test/test-zlib-write-after-close.js b/test/test-zlib-write-after-close.js
new file mode 100644
index 0000000..827a4bf
--- /dev/null
+++ b/test/test-zlib-write-after-close.js
@@ -0,0 +1,20 @@
+'use strict';
+
+var assert = require('assert');
+var zlib = require('../');
+
+var closed = false;
+
+zlib.gzip('hello', function(err, out) {
+ var unzip = zlib.createGunzip();
+ unzip.close(function() {
+ closed = true;
+ });
+ assert.throws(function() {
+ unzip.write(out);
+ });
+});
+
+process.on('exit', function() {
+ assert(closed);
+});
diff --git a/test/test-zlib-write-after-flush.js b/test/test-zlib-write-after-flush.js
index 5841ef8..4ba2384 100755
--- a/test/test-zlib-write-after-flush.js
+++ b/test/test-zlib-write-after-flush.js
@@ -1,55 +1,33 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var tape = require('tape');
+'use strict';
+
+var assert = require('assert');
var zlib = require('../');
-var fs = require('fs');
-
-tape('write after flush', function(t) {
- t.plan(2);
-
- var gzip = zlib.createGzip();
- var gunz = zlib.createUnzip();
-
- gzip.pipe(gunz);
-
- var output = '';
- var input = 'A line of data\n';
- gunz.setEncoding('utf8');
- gunz.on('data', function(c) {
- output += c;
- });
-
- gunz.on('end', function() {
- t.equal(output, input);
-
- // Make sure that the flush flag was set back to normal
- t.equal(gzip._flushFlag, zlib.Z_NO_FLUSH);
- });
-
- // make sure that flush/write doesn't trigger an assert failure
- gzip.flush(); write();
- function write() {
- gzip.write(input);
- gzip.end();
- gunz.read(0);
- }
+
+var gzip = zlib.createGzip();
+var gunz = zlib.createUnzip();
+
+gzip.pipe(gunz);
+
+var output = '';
+var input = 'A line of data\n';
+gunz.setEncoding('utf8');
+gunz.on('data', function(c) {
+ output += c;
});
+
+process.on('exit', function() {
+ assert.equal(output, input);
+
+ // Make sure that the flush flag was set back to normal
+ assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH);
+
+ console.log('ok');
+});
+
+// make sure that flush/write doesn't trigger an assert failure
+gzip.flush(); write();
+function write() {
+ gzip.write(input);
+ gzip.end();
+ gunz.read(0);
+}
diff --git a/test/test-zlib-zero-byte.js b/test/test-zlib-zero-byte.js
index 88bdd8c..cc77f70 100755
--- a/test/test-zlib-zero-byte.js
+++ b/test/test-zlib-zero-byte.js
@@ -1,41 +1,28 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
+'use strict';
+
+var assert = require('assert');
-var tape = require('tape');
var zlib = require('../');
+var gz = zlib.Gzip();
+var emptyBuffer = new Buffer(0);
+var received = 0;
+gz.on('data', function(c) {
+ received += c.length;
+});
+var ended = false;
+gz.on('end', function() {
+ ended = true;
+});
+var finished = false;
+gz.on('finish', function() {
+ finished = true;
+});
+gz.write(emptyBuffer);
+gz.end();
-tape('zero byte', function(t) {
- t.plan(2);
- var gz = zlib.Gzip()
- var emptyBuffer = new Buffer(0);
- var received = 0;
- gz.on('data', function(c) {
- received += c.length;
- });
- gz.on('end', function() {
- t.equal(received, 20);
- });
- gz.on('finish', function() {
- t.ok(true);
- });
- gz.write(emptyBuffer);
- gz.end();
+process.on('exit', function() {
+ assert.equal(received, 20);
+ assert(ended);
+ assert(finished);
+ console.log('ok');
});
diff --git a/test/test-zlib.js b/test/test-zlib.js
index 64c02c5..9e16c64 100644
--- a/test/test-zlib.js
+++ b/test/test-zlib.js
@@ -1,24 +1,5 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+'use strict';
+var common = require('./common');
var assert = require('assert');
var zlib = require('../');
var path = require('path');
@@ -57,15 +38,17 @@ if (!process.env.PUMMEL) {
var fs = require('fs');
+var testFiles = ['person.jpg', 'elipses.txt', 'empty.txt'];
+
if (process.env.FAST) {
zlibPairs = [[zlib.Gzip, zlib.Unzip]];
+ testFiles = ['person.jpg'];
}
-var tests = {
- 'person.jpg': fs.readFileSync(__dirname + '/fixtures/person.jpg'),
- 'elipses.txt': fs.readFileSync(__dirname + '/fixtures/elipses.txt'),
- 'empty.txt': fs.readFileSync(__dirname + '/fixtures/empty.txt')
-};
+var tests = {};
+testFiles.forEach(function(file) {
+ tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file));
+});
var util = require('util');
var stream = require('stream');
@@ -142,19 +125,19 @@ SlowStream.prototype.resume = function() {
SlowStream.prototype.end = function(chunk) {
// walk over the chunk in blocks.
- var self = this;
- self.chunk = chunk;
- self.length = chunk.length;
- self.resume();
- return self.ended;
+ this.chunk = chunk;
+ this.length = chunk.length;
+ this.resume();
+ return this.ended;
};
-
// for each of the files, make sure that compressing and
// decompressing results in the same data, for every combination
// of the options set above.
-var tape = require('tape');
+var failures = 0;
+var total = 0;
+var done = 0;
Object.keys(tests).forEach(function(file) {
var test = tests[file];
@@ -167,40 +150,58 @@ Object.keys(tests).forEach(function(file) {
zlibPairs.forEach(function(pair) {
var Def = pair[0];
var Inf = pair[1];
- var opts = {
- level: level,
+ var opts = { level: level,
windowBits: windowBits,
memLevel: memLevel,
- strategy: strategy
- };
-
- var msg = file + ' ' +
- chunkSize + ' ' +
- JSON.stringify(opts) + ' ' +
- Def.name + ' -> ' + Inf.name;
-
- tape('zlib ' + msg, function(t) {
- t.plan(1);
-
- var def = new Def(opts);
- var inf = new Inf(opts);
- var ss = new SlowStream(trickle);
- var buf = new BufferStream();
-
- // verify that the same exact buffer comes out the other end.
- buf.on('data', function(c) {
- t.deepEqual(c, test);
- });
-
- // the magic happens here.
- ss.pipe(def).pipe(inf).pipe(buf);
- ss.end(test);
+ strategy: strategy };
+
+ total++;
+
+ var def = new Def(opts);
+ var inf = new Inf(opts);
+ var ss = new SlowStream(trickle);
+ var buf = new BufferStream();
+
+ // verify that the same exact buffer comes out the other end.
+ buf.on('data', function(c) {
+ var msg = file + ' ' +
+ chunkSize + ' ' +
+ JSON.stringify(opts) + ' ' +
+ Def.name + ' -> ' + Inf.name;
+ var ok = true;
+ var testNum = ++done;
+ for (var i = 0; i < Math.max(c.length, test.length); i++) {
+ if (c[i] !== test[i]) {
+ ok = false;
+ failures++;
+ break;
+ }
+ }
+ if (ok) {
+ console.log('ok ' + (testNum) + ' ' + msg);
+ } else {
+ console.log('not ok ' + (testNum) + ' ' + msg);
+ console.log(' ...');
+ console.log(' testfile: ' + file);
+ console.log(' type: ' + Def.name + ' -> ' + Inf.name);
+ console.log(' position: ' + i);
+ console.log(' options: ' + JSON.stringify(opts));
+ console.log(' expect: ' + test[i]);
+ console.log(' actual: ' + c[i]);
+ console.log(' chunkSize: ' + chunkSize);
+ console.log(' ---');
+ }
});
+
+ // the magic happens here.
+ ss.pipe(def).pipe(inf).pipe(buf);
+ ss.end(test);
});
- });
- });
- });
- });
- });
- });
+ }); }); }); }); }); }); // sad stallman is sad.
+});
+
+process.on('exit', function(code) {
+ console.log('1..' + done);
+ assert.equal(done, total, (total - done) + ' tests left unfinished');
+ assert.ok(!failures, 'some test failures');
});
diff --git a/test/tmp/person.jpg b/test/tmp/person.jpg
new file mode 100644
index 0000000..e69de29
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-zlib.git
More information about the Pkg-javascript-commits
mailing list