[Pkg-javascript-commits] [node-browserify-zlib] 02/50: Linting and mocha

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 470dfe47d3967180fbbaf306dbb9c8be3f3b726c
Author: dignifiedquire <dignifiedquire at gmail.com>
Date:   Thu Mar 31 13:24:43 2016 -0400

    Linting and mocha
---
 .travis.yml                                        |  10 +-
 package.json                                       |  16 +-
 src/binding.js                                     | 289 ++++----
 src/index.js                                       | 773 ++++++++++-----------
 test/common.js                                     | 119 ++--
 test/fixtures/person.jpg.gz                        | Bin 0 -> 45429 bytes
 test/ignored/test-zlib-from-concatenated-gzip.js   |  18 +-
 .../test-zlib-from-gzip-with-trailing-garbage.js   |  36 +-
 test/index.js                                      |  16 -
 test/test-zlib-close-after-write.js                |  31 +-
 test/test-zlib-const.js                            |  22 +-
 test/test-zlib-convenience-methods.js              | 109 +--
 test/test-zlib-dictionary-fail.js                  |  53 +-
 test/test-zlib-dictionary.js                       | 135 ++--
 test/test-zlib-flush-drain.js                      |  87 +--
 test/test-zlib-flush.js                            |  71 +-
 test/test-zlib-from-gzip.js                        |  52 +-
 test/test-zlib-from-string.js                      | 117 ++--
 test/test-zlib-invalid-input.js                    |  83 ++-
 test/test-zlib-params.js                           |  67 +-
 test/test-zlib-random-byte-pipes.js                | 207 +++---
 test/test-zlib-truncated.js                        |  50 +-
 test/test-zlib-write-after-close.js                |  36 +-
 test/test-zlib-write-after-flush.js                |  44 +-
 test/test-zlib-zero-byte.js                        |  50 +-
 test/test-zlib.js                                  | 333 +++++----
 test/tmp/person.jpg                                | Bin 0 -> 45658 bytes
 27 files changed, 1452 insertions(+), 1372 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 88c3419..96be99c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,9 @@
 language: node_js
 node_js:
-  - "0.10"
-  - 4.0
-  - 5.0
+  - '4'
+  - '5'
+  - stable
+
+script:
+  - npm run lint
+  - npm test
diff --git a/package.json b/package.json
index 69af38f..6e9f560 100644
--- a/package.json
+++ b/package.json
@@ -2,8 +2,11 @@
   "name": "browserify-zlib",
   "version": "0.1.4",
   "description": "Full zlib module for browserify",
-  "keywords": ["zlib", "browserify"],
-  "main": "index.js",
+  "keywords": [
+    "zlib",
+    "browserify"
+  ],
+  "main": "src/index.js",
   "directories": {
     "test": "test"
   },
@@ -11,8 +14,9 @@
     "pako": "~1.0.0"
   },
   "devDependencies": {
-    "tape": "^4.5.1",
-    "brfs": "^1.0.1"
+    "brfs": "^1.0.1",
+    "mocha": "^2.4.5",
+    "standard": "^6.0.8"
   },
   "testling": {
     "files": "test/*.js",
@@ -28,9 +32,9 @@
     ]
   },
   "scripts": {
-    "test": "node_modules/tape/bin/tape test/*.js"
+    "lint": "standard",
+    "test": "mocha test/test-*"
   },
-  "main": "src/index.js",
   "author": "Devon Govett <devongovett at gmail.com>",
   "license": "MIT",
   "repository": {
diff --git a/src/binding.js b/src/binding.js
index 6a22fe9..c7a7599 100644
--- a/src/binding.js
+++ b/src/binding.js
@@ -1,236 +1,247 @@
-var msg = require('pako/lib/zlib/messages');
-var zstream = require('pako/lib/zlib/zstream');
-var zlib_deflate = require('pako/lib/zlib/deflate.js');
-var zlib_inflate = require('pako/lib/zlib/inflate.js');
-var constants = require('pako/lib/zlib/constants');
+var msg = require('pako/lib/zlib/messages')
+var Zstream = require('pako/lib/zlib/zstream')
+var zlib_deflate = require('pako/lib/zlib/deflate.js')
+var zlib_inflate = require('pako/lib/zlib/inflate.js')
+var constants = require('pako/lib/zlib/constants')
 
 for (var key in constants) {
-  exports[key] = constants[key];
+  exports[key] = constants[key]
 }
 
 // zlib modes
-exports.NONE = 0;
-exports.DEFLATE = 1;
-exports.INFLATE = 2;
-exports.GZIP = 3;
-exports.GUNZIP = 4;
-exports.DEFLATERAW = 5;
-exports.INFLATERAW = 6;
-exports.UNZIP = 7;
+exports.NONE = 0
+exports.DEFLATE = 1
+exports.INFLATE = 2
+exports.GZIP = 3
+exports.GUNZIP = 4
+exports.DEFLATERAW = 5
+exports.INFLATERAW = 6
+exports.UNZIP = 7
 
 /**
  * Emulate Node's zlib C++ layer for use by the JS layer in index.js
  */
-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;
-  this.pending_close = false;
-  this.windowBits = 0;
-  this.level = 0;
-  this.memLevel = 0;
-  this.strategy = 0;
-  this.dictionary = null;
+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
+  this.pending_close = false
+  this.windowBits = 0
+  this.level = 0
+  this.memLevel = 0
+  this.strategy = 0
+  this.dictionary = null
 }
 
-Zlib.prototype.init = function(windowBits, level, memLevel, strategy, dictionary) {
-  this.windowBits = windowBits;
-  this.level = level;
-  this.memLevel = memLevel;
-  this.strategy = strategy;
+Zlib.prototype.init = function (windowBits, level, memLevel, strategy, dictionary) {
+  this.windowBits = windowBits
+  this.level = level
+  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.GZIP || this.mode === exports.GUNZIP) {
+    this.windowBits += 16
+  }
 
-  if (this.mode === exports.UNZIP)
-    this.windowBits += 32;
+  if (this.mode === exports.UNZIP) {
+    this.windowBits += 32
+  }
 
-  if (this.mode === exports.DEFLATERAW || this.mode === exports.INFLATERAW)
-    this.windowBits = -this.windowBits;
+  if (this.mode === exports.DEFLATERAW || this.mode === exports.INFLATERAW) {
+    this.windowBits = -this.windowBits
+  }
 
-  this.strm = new zstream();
+  this.strm = new Zstream()
+  var status
 
   switch (this.mode) {
     case exports.DEFLATE:
     case exports.GZIP:
     case exports.DEFLATERAW:
-      var status = zlib_deflate.deflateInit2(
+      status = zlib_deflate.deflateInit2(
         this.strm,
         this.level,
         exports.Z_DEFLATED,
         this.windowBits,
         this.memLevel,
         this.strategy
-      );
-      break;
+      )
+      break
     case exports.INFLATE:
     case exports.GUNZIP:
     case exports.INFLATERAW:
     case exports.UNZIP:
-      var status  = zlib_inflate.inflateInit2(
+      status = zlib_inflate.inflateInit2(
         this.strm,
         this.windowBits
-      );
-      break;
+      )
+      break
     default:
-      throw new Error("Unknown mode " + this.mode);
+      throw new Error('Unknown mode ' + this.mode)
   }
 
   if (status !== exports.Z_OK) {
-    this._error(status);
-    return;
+    this._error(status)
+    return
   }
 
-  this.write_in_progress = false;
-  this.init_done = true;
-};
-
-Zlib.prototype.params = function() {
-  throw new Error("deflateParams Not supported");
-};
-
-Zlib.prototype._writeCheck = function() {
-  if (!this.init_done)
-    throw new Error("write before init");
-
-  if (this.mode === exports.NONE)
-    throw new Error("already finalized");
+  this.write_in_progress = false
+  this.init_done = true
+}
 
-  if (this.write_in_progress)
-    throw new Error("write already in progress");
+Zlib.prototype.params = function () {
+  throw new Error('deflateParams Not supported')
+}
 
-  if (this.pending_close)
-    throw new Error("close is pending");
-};
+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) {
-  this._writeCheck();
-  this.write_in_progress = true;
+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]);
+  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();
-  });
+    if (self.pending_close) {
+      self.close()
+    }
+  })
 
-  return this;
-};
+  return this
+}
 
 // set method for Node buffers, used by pako
-function bufferSet(data, offset) {
+function bufferSet (data, offset) {
   for (var i = 0; i < data.length; i++) {
-    this[offset + i] = data[i];
+    this[offset + i] = data[i]
   }
 }
 
-Zlib.prototype.writeSync = function(flush, input, in_off, in_len, out, out_off, out_len) {
-  this._writeCheck();
-  return this._write(flush, input, in_off, in_len, out, out_off, out_len);
-};
+Zlib.prototype.writeSync = function (flush, input, in_off, in_len, out, out_off, out_len) {
+  this._writeCheck()
+  return this._write(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.write_in_progress = true;
+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 &&
-      flush !== exports.Z_FULL_FLUSH &&
-      flush !== exports.Z_FINISH &&
-      flush !== exports.Z_BLOCK) {
-    throw new Error("Invalid flush value");
+    flush !== exports.Z_PARTIAL_FLUSH &&
+    flush !== exports.Z_SYNC_FLUSH &&
+    flush !== exports.Z_FULL_FLUSH &&
+    flush !== exports.Z_FINISH &&
+    flush !== exports.Z_BLOCK) {
+    throw new Error('Invalid flush value')
   }
 
   if (input == null) {
-    input = new Buffer(0);
-    in_len = 0;
-    in_off = 0;
+    input = new Buffer(0)
+    in_len = 0
+    in_off = 0
   }
 
-  if (out._set)
-    out.set = out._set;
-  else
-    out.set = bufferSet;
+  if (out._set) {
+    out.set = out._set
+  } else {
+    out.set = bufferSet
+  }
 
-  var strm = this.strm;
-  strm.avail_in = in_len;
-  strm.input = input;
-  strm.next_in = in_off;
-  strm.avail_out = out_len;
-  strm.output = out;
-  strm.next_out = out_off;
+  var strm = this.strm
+  strm.avail_in = in_len
+  strm.input = input
+  strm.next_in = in_off
+  strm.avail_out = out_len
+  strm.output = out
+  strm.next_out = out_off
 
+  var status
   switch (this.mode) {
     case exports.DEFLATE:
     case exports.GZIP:
     case exports.DEFLATERAW:
-      var status = zlib_deflate.deflate(strm, flush);
-      break;
+      status = zlib_deflate.deflate(strm, flush)
+      break
     case exports.UNZIP:
     case exports.INFLATE:
     case exports.GUNZIP:
     case exports.INFLATERAW:
-      var status = zlib_inflate.inflate(strm, flush);
-      break;
+      status = zlib_inflate.inflate(strm, flush)
+      break
     default:
-      throw new Error("Unknown mode " + this.mode);
+      throw new Error('Unknown mode ' + this.mode)
   }
 
   if (status !== exports.Z_STREAM_END && status !== exports.Z_OK) {
-    this._error(status);
+    this._error(status)
   }
 
-  this.write_in_progress = false;
-  return [strm.avail_in, strm.avail_out];
-};
+  this.write_in_progress = false
+  return [strm.avail_in, strm.avail_out]
+}
 
-Zlib.prototype.close = function() {
+Zlib.prototype.close = function () {
   if (this.write_in_progress) {
-    this.pending_close = true;
-    return;
+    this.pending_close = true
+    return
   }
 
-  this.pending_close = false;
+  this.pending_close = false
 
   if (this.mode === exports.DEFLATE || this.mode === exports.GZIP || this.mode === exports.DEFLATERAW) {
-    zlib_deflate.deflateEnd(this.strm);
+    zlib_deflate.deflateEnd(this.strm)
   } else {
-    zlib_inflate.inflateEnd(this.strm);
+    zlib_inflate.inflateEnd(this.strm)
   }
 
-  this.mode = exports.NONE;
-};
+  this.mode = exports.NONE
+}
 
-Zlib.prototype.reset = function() {
+Zlib.prototype.reset = function () {
+  var status
   switch (this.mode) {
     case exports.DEFLATE:
     case exports.DEFLATERAW:
-      var status = zlib_deflate.deflateReset(this.strm);
-      break;
+      status = zlib_deflate.deflateReset(this.strm)
+      break
     case exports.INFLATE:
     case exports.INFLATERAW:
-      var status = zlib_inflate.inflateReset(this.strm);
-      break;
+      status = zlib_inflate.inflateReset(this.strm)
+      break
   }
 
   if (status !== exports.Z_OK) {
-    this._error(status);
+    this._error(status)
   }
-};
+}
 
-Zlib.prototype._error = function(status) {
-  this.onerror(msg[status] + ': ' + this.strm.msg, status);
+Zlib.prototype._error = function (status) {
+  this.onerror(msg[status] + ': ' + this.strm.msg, status)
 
-  this.write_in_progress = false;
-  if (this.pending_close)
-    this.close();
-};
+  this.write_in_progress = false
+  if (this.pending_close) {
+    this.close()
+  }
+}
 
-exports.Zlib = Zlib;
+exports.Zlib = Zlib
diff --git a/src/index.js b/src/index.js
index 5d4d01c..b955971 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,69 +1,48 @@
-// 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';
-
-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.';
+'use strict'
+
+var Buffer = require('buffer').Buffer
+var Transform = require('_stream_transform')
+var binding = require('./binding')
+var util = require('util')
+var assert = require('assert').ok
+var kMaxLength = require('buffer').kMaxLength
+var 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.
-binding.Z_MIN_WINDOWBITS = 8;
-binding.Z_MAX_WINDOWBITS = 15;
-binding.Z_DEFAULT_WINDOWBITS = 15;
+// var naming scheme zlib uses.
+binding.Z_MIN_WINDOWBITS = 8
+binding.Z_MAX_WINDOWBITS = 15
+binding.Z_DEFAULT_WINDOWBITS = 15
 
 // fewer than 64 bytes per chunk is stupid.
 // technically it could work with as few as 8, but even 64 bytes
 // is absurdly low.  Usually a MB or more is best.
-binding.Z_MIN_CHUNK = 64;
-binding.Z_MAX_CHUNK = Infinity;
-binding.Z_DEFAULT_CHUNK = (16 * 1024);
+binding.Z_MIN_CHUNK = 64
+binding.Z_MAX_CHUNK = Infinity
+binding.Z_DEFAULT_CHUNK = (16 * 1024)
 
-binding.Z_MIN_MEMLEVEL = 1;
-binding.Z_MAX_MEMLEVEL = 9;
-binding.Z_DEFAULT_MEMLEVEL = 8;
+binding.Z_MIN_MEMLEVEL = 1
+binding.Z_MAX_MEMLEVEL = 9
+binding.Z_DEFAULT_MEMLEVEL = 8
 
-binding.Z_MIN_LEVEL = -1;
-binding.Z_MAX_LEVEL = 9;
-binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION;
+binding.Z_MIN_LEVEL = -1
+binding.Z_MAX_LEVEL = 9
+binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION
 
-// expose all the zlib constants
-const bkeys = Object.keys(binding);
+// expose all the zlib varants
+var bkeys = Object.keys(binding)
 for (var bk = 0; bk < bkeys.length; bk++) {
-  var bkey = bkeys[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.
-const codes = {
+var codes = {
   Z_OK: binding.Z_OK,
   Z_STREAM_END: binding.Z_STREAM_END,
   Z_NEED_DICT: binding.Z_NEED_DICT,
@@ -73,535 +52,542 @@ const codes = {
   Z_MEM_ERROR: binding.Z_MEM_ERROR,
   Z_BUF_ERROR: binding.Z_BUF_ERROR,
   Z_VERSION_ERROR: binding.Z_VERSION_ERROR
-};
+}
 
-const ckeys = Object.keys(codes);
+var ckeys = Object.keys(codes)
 for (var ck = 0; ck < ckeys.length; ck++) {
-  var ckey = ckeys[ck];
-  codes[codes[ckey]] = ckey;
+  var ckey = ckeys[ck]
+  codes[codes[ckey]] = ckey
 }
 
 Object.defineProperty(exports, 'codes', {
   enumerable: true, value: Object.freeze(codes), writable: false
-});
-
-exports.Deflate = Deflate;
-exports.Inflate = Inflate;
-exports.Gzip = Gzip;
-exports.Gunzip = Gunzip;
-exports.DeflateRaw = DeflateRaw;
-exports.InflateRaw = InflateRaw;
-exports.Unzip = Unzip;
-
-exports.createDeflate = function(o) {
-  return new Deflate(o);
-};
-
-exports.createInflate = function(o) {
-  return new Inflate(o);
-};
+})
+
+exports.Deflate = Deflate
+exports.Inflate = Inflate
+exports.Gzip = Gzip
+exports.Gunzip = Gunzip
+exports.DeflateRaw = DeflateRaw
+exports.InflateRaw = InflateRaw
+exports.Unzip = Unzip
+
+exports.createDeflate = function (o) {
+  return new Deflate(o)
+}
 
-exports.createDeflateRaw = function(o) {
-  return new DeflateRaw(o);
-};
+exports.createInflate = function (o) {
+  return new Inflate(o)
+}
 
-exports.createInflateRaw = function(o) {
-  return new InflateRaw(o);
-};
+exports.createDeflateRaw = function (o) {
+  return new DeflateRaw(o)
+}
 
-exports.createGzip = function(o) {
-  return new Gzip(o);
-};
+exports.createInflateRaw = function (o) {
+  return new InflateRaw(o)
+}
 
-exports.createGunzip = function(o) {
-  return new Gunzip(o);
-};
+exports.createGzip = function (o) {
+  return new Gzip(o)
+}
 
-exports.createUnzip = function(o) {
-  return new Unzip(o);
-};
+exports.createGunzip = function (o) {
+  return new Gunzip(o)
+}
 
+exports.createUnzip = function (o) {
+  return new Unzip(o)
+}
 
 // Convenience methods.
 // compress/decompress a string or buffer in one step.
-exports.deflate = function(buffer, opts, callback) {
+exports.deflate = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new Deflate(opts), buffer, callback);
-};
+  return zlibBuffer(new Deflate(opts), buffer, callback)
+}
 
-exports.deflateSync = function(buffer, opts) {
-  return zlibBufferSync(new Deflate(opts), buffer);
-};
+exports.deflateSync = function (buffer, opts) {
+  return zlibBufferSync(new Deflate(opts), buffer)
+}
 
-exports.gzip = function(buffer, opts, callback) {
+exports.gzip = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new Gzip(opts), buffer, callback);
-};
+  return zlibBuffer(new Gzip(opts), buffer, callback)
+}
 
-exports.gzipSync = function(buffer, opts) {
-  return zlibBufferSync(new Gzip(opts), buffer);
-};
+exports.gzipSync = function (buffer, opts) {
+  return zlibBufferSync(new Gzip(opts), buffer)
+}
 
-exports.deflateRaw = function(buffer, opts, callback) {
+exports.deflateRaw = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new DeflateRaw(opts), buffer, callback);
-};
+  return zlibBuffer(new DeflateRaw(opts), buffer, callback)
+}
 
-exports.deflateRawSync = function(buffer, opts) {
-  return zlibBufferSync(new DeflateRaw(opts), buffer);
-};
+exports.deflateRawSync = function (buffer, opts) {
+  return zlibBufferSync(new DeflateRaw(opts), buffer)
+}
 
-exports.unzip = function(buffer, opts, callback) {
+exports.unzip = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new Unzip(opts), buffer, callback);
-};
+  return zlibBuffer(new Unzip(opts), buffer, callback)
+}
 
-exports.unzipSync = function(buffer, opts) {
-  return zlibBufferSync(new Unzip(opts), buffer);
-};
+exports.unzipSync = function (buffer, opts) {
+  return zlibBufferSync(new Unzip(opts), buffer)
+}
 
-exports.inflate = function(buffer, opts, callback) {
+exports.inflate = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new Inflate(opts), buffer, callback);
-};
+  return zlibBuffer(new Inflate(opts), buffer, callback)
+}
 
-exports.inflateSync = function(buffer, opts) {
-  return zlibBufferSync(new Inflate(opts), buffer);
-};
+exports.inflateSync = function (buffer, opts) {
+  return zlibBufferSync(new Inflate(opts), buffer)
+}
 
-exports.gunzip = function(buffer, opts, callback) {
+exports.gunzip = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new Gunzip(opts), buffer, callback);
-};
+  return zlibBuffer(new Gunzip(opts), buffer, callback)
+}
 
-exports.gunzipSync = function(buffer, opts) {
-  return zlibBufferSync(new Gunzip(opts), buffer);
-};
+exports.gunzipSync = function (buffer, opts) {
+  return zlibBufferSync(new Gunzip(opts), buffer)
+}
 
-exports.inflateRaw = function(buffer, opts, callback) {
+exports.inflateRaw = function (buffer, opts, callback) {
   if (typeof opts === 'function') {
-    callback = opts;
-    opts = {};
+    callback = opts
+    opts = {}
   }
-  return zlibBuffer(new InflateRaw(opts), buffer, callback);
-};
+  return zlibBuffer(new InflateRaw(opts), buffer, callback)
+}
 
-exports.inflateRawSync = function(buffer, opts) {
-  return zlibBufferSync(new InflateRaw(opts), buffer);
-};
+exports.inflateRawSync = function (buffer, opts) {
+  return zlibBufferSync(new InflateRaw(opts), buffer)
+}
 
-function zlibBuffer(engine, buffer, callback) {
-  var buffers = [];
-  var nread = 0;
+function zlibBuffer (engine, buffer, callback) {
+  var buffers = []
+  var nread = 0
 
-  engine.on('error', onError);
-  engine.on('end', onEnd);
+  engine.on('error', onError)
+  engine.on('end', onEnd)
 
-  engine.end(buffer);
-  flow();
+  engine.end(buffer)
+  flow()
 
-  function flow() {
-    var chunk;
+  function flow () {
+    var chunk
+    // eslint-disable-next-line
     while (null !== (chunk = engine.read())) {
-      buffers.push(chunk);
-      nread += chunk.length;
+      buffers.push(chunk)
+      nread += chunk.length
     }
-    engine.once('readable', flow);
+    engine.once('readable', flow)
   }
 
-  function onError(err) {
-    engine.removeListener('end', onEnd);
-    engine.removeListener('readable', flow);
-    callback(err);
+  function onError (err) {
+    engine.removeListener('end', onEnd)
+    engine.removeListener('readable', flow)
+    callback(err)
   }
 
-  function onEnd() {
-    var buf;
-    var err = null;
+  function onEnd () {
+    var buf
+    var err = null
 
     if (nread >= kMaxLength) {
-      err = new RangeError(kRangeErrorMessage);
+      err = new RangeError(kRangeErrorMessage)
     } else {
-      buf = Buffer.concat(buffers, nread);
+      buf = Buffer.concat(buffers, nread)
     }
 
-    buffers = [];
-    engine.close();
-    callback(err, buf);
+    buffers = []
+    engine.close()
+    callback(err, buf)
   }
 }
 
-function zlibBufferSync(engine, buffer) {
-  if (typeof buffer === 'string')
-    buffer = new Buffer(buffer);
-  if (!(buffer instanceof Buffer))
-    throw new TypeError('Not a string or buffer');
-
-  var flushFlag = binding.Z_FINISH;
+function zlibBufferSync (engine, buffer) {
+  if (typeof buffer === 'string') {
+    buffer = new Buffer(buffer)
+  }
+  if (!(buffer instanceof Buffer)) {
+    throw new TypeError('Not a string or buffer')
+  }
+  var flushFlag = binding.Z_FINISH
 
-  return engine._processChunk(buffer, flushFlag);
+  return engine._processChunk(buffer, flushFlag)
 }
 
 // generic zlib
 // minimal 2-byte header
-function Deflate(opts) {
-  if (!(this instanceof Deflate)) return new Deflate(opts);
-  Zlib.call(this, opts, binding.DEFLATE);
+function Deflate (opts) {
+  if (!(this instanceof Deflate)) return new Deflate(opts)
+  Zlib.call(this, opts, binding.DEFLATE)
 }
 
-function Inflate(opts) {
-  if (!(this instanceof Inflate)) return new Inflate(opts);
-  Zlib.call(this, opts, binding.INFLATE);
+function Inflate (opts) {
+  if (!(this instanceof Inflate)) return new Inflate(opts)
+  Zlib.call(this, opts, binding.INFLATE)
 }
 
-
 // gzip - bigger header, same deflate compression
-function Gzip(opts) {
-  if (!(this instanceof Gzip)) return new Gzip(opts);
-  Zlib.call(this, opts, binding.GZIP);
+function Gzip (opts) {
+  if (!(this instanceof Gzip)) return new Gzip(opts)
+  Zlib.call(this, opts, binding.GZIP)
 }
 
-function Gunzip(opts) {
-  if (!(this instanceof Gunzip)) return new Gunzip(opts);
-  Zlib.call(this, opts, binding.GUNZIP);
+function Gunzip (opts) {
+  if (!(this instanceof Gunzip)) return new Gunzip(opts)
+  Zlib.call(this, opts, binding.GUNZIP)
 }
 
-
 // raw - no header
-function DeflateRaw(opts) {
-  if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts);
-  Zlib.call(this, opts, binding.DEFLATERAW);
+function DeflateRaw (opts) {
+  if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts)
+  Zlib.call(this, opts, binding.DEFLATERAW)
 }
 
-function InflateRaw(opts) {
-  if (!(this instanceof InflateRaw)) return new InflateRaw(opts);
-  Zlib.call(this, opts, binding.INFLATERAW);
+function InflateRaw (opts) {
+  if (!(this instanceof InflateRaw)) return new InflateRaw(opts)
+  Zlib.call(this, opts, binding.INFLATERAW)
 }
 
-
 // auto-detect header.
-function Unzip(opts) {
-  if (!(this instanceof Unzip)) return new Unzip(opts);
-  Zlib.call(this, opts, binding.UNZIP);
+function Unzip (opts) {
+  if (!(this instanceof Unzip)) return new Unzip(opts)
+  Zlib.call(this, opts, binding.UNZIP)
 }
 
-
 // the Zlib class they all inherit from
 // This thing manages the queue of requests, and returns
 // true or false if there is anything in the queue when
 // you call the .write() method.
 
-function Zlib(opts, mode) {
-  this._opts = opts = opts || {};
-  this._chunkSize = opts.chunkSize || exports.Z_DEFAULT_CHUNK;
+function Zlib (opts, mode) {
+  this._opts = opts = opts || {}
+  this._chunkSize = opts.chunkSize || exports.Z_DEFAULT_CHUNK
 
-  Transform.call(this, opts);
+  Transform.call(this, opts)
 
   if (opts.flush) {
     if (opts.flush !== binding.Z_NO_FLUSH &&
-        opts.flush !== binding.Z_PARTIAL_FLUSH &&
-        opts.flush !== binding.Z_SYNC_FLUSH &&
-        opts.flush !== binding.Z_FULL_FLUSH &&
-        opts.flush !== binding.Z_FINISH &&
-        opts.flush !== binding.Z_BLOCK) {
-      throw new Error('Invalid flush flag: ' + opts.flush);
+      opts.flush !== binding.Z_PARTIAL_FLUSH &&
+      opts.flush !== binding.Z_SYNC_FLUSH &&
+      opts.flush !== binding.Z_FULL_FLUSH &&
+      opts.flush !== binding.Z_FINISH &&
+      opts.flush !== binding.Z_BLOCK) {
+      throw new Error('Invalid flush flag: ' + opts.flush)
     }
   }
-  this._flushFlag = opts.flush || binding.Z_NO_FLUSH;
+  this._flushFlag = opts.flush || binding.Z_NO_FLUSH
 
   if (opts.chunkSize) {
     if (opts.chunkSize < exports.Z_MIN_CHUNK ||
-        opts.chunkSize > exports.Z_MAX_CHUNK) {
-      throw new Error('Invalid chunk size: ' + opts.chunkSize);
+      opts.chunkSize > exports.Z_MAX_CHUNK) {
+      throw new Error('Invalid chunk size: ' + opts.chunkSize)
     }
   }
 
   if (opts.windowBits) {
     if (opts.windowBits < exports.Z_MIN_WINDOWBITS ||
-        opts.windowBits > exports.Z_MAX_WINDOWBITS) {
-      throw new Error('Invalid windowBits: ' + opts.windowBits);
+      opts.windowBits > exports.Z_MAX_WINDOWBITS) {
+      throw new Error('Invalid windowBits: ' + opts.windowBits)
     }
   }
 
   if (opts.level) {
     if (opts.level < exports.Z_MIN_LEVEL ||
-        opts.level > exports.Z_MAX_LEVEL) {
-      throw new Error('Invalid compression level: ' + opts.level);
+      opts.level > exports.Z_MAX_LEVEL) {
+      throw new Error('Invalid compression level: ' + opts.level)
     }
   }
 
   if (opts.memLevel) {
     if (opts.memLevel < exports.Z_MIN_MEMLEVEL ||
-        opts.memLevel > exports.Z_MAX_MEMLEVEL) {
-      throw new Error('Invalid memLevel: ' + opts.memLevel);
+      opts.memLevel > exports.Z_MAX_MEMLEVEL) {
+      throw new Error('Invalid memLevel: ' + opts.memLevel)
     }
   }
 
   if (opts.strategy) {
-    if (opts.strategy != exports.Z_FILTERED &&
-        opts.strategy != exports.Z_HUFFMAN_ONLY &&
-        opts.strategy != exports.Z_RLE &&
-        opts.strategy != exports.Z_FIXED &&
-        opts.strategy != exports.Z_DEFAULT_STRATEGY) {
-      throw new Error('Invalid strategy: ' + opts.strategy);
+    if (opts.strategy !== exports.Z_FILTERED &&
+      opts.strategy !== exports.Z_HUFFMAN_ONLY &&
+      opts.strategy !== exports.Z_RLE &&
+      opts.strategy !== exports.Z_FIXED &&
+      opts.strategy !== exports.Z_DEFAULT_STRATEGY) {
+      throw new Error('Invalid strategy: ' + opts.strategy)
     }
   }
 
   if (opts.dictionary) {
     if (!(opts.dictionary instanceof Buffer)) {
-      throw new Error('Invalid dictionary: it should be a Buffer instance');
+      throw new Error('Invalid dictionary: it should be a Buffer instance')
     }
   }
 
-  this._handle = new binding.Zlib(mode);
+  this._handle = new binding.Zlib(mode)
 
-  var self = this;
-  this._hadError = false;
-  this._handle.onerror = function(message, errno) {
+  var self = this
+  this._hadError = false
+  this._handle.onerror = function (message, errno) {
     // there is no way to cleanly recover.
     // continuing only obscures problems.
-    self._handle = null;
-    self._hadError = true;
-
-    var error = new Error(message);
-    error.errno = errno;
-    error.code = exports.codes[errno];
-    self.emit('error', error);
-  };
+    self._handle = null
+    self._hadError = true
 
-  var level = exports.Z_DEFAULT_COMPRESSION;
-  if (typeof opts.level === 'number') level = opts.level;
+    var error = new Error(message)
 
-  var strategy = exports.Z_DEFAULT_STRATEGY;
-  if (typeof opts.strategy === 'number') strategy = opts.strategy;
+    error.errno = errno
+    error.code = exports.codes[errno]
+    self.emit('error', error)
+  }
 
-  this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS,
-                    level,
-                    opts.memLevel || exports.Z_DEFAULT_MEMLEVEL,
-                    strategy,
-                    opts.dictionary);
+  var level = exports.Z_DEFAULT_COMPRESSION
+  if (typeof opts.level === 'number') level = opts.level
 
-  this._buffer = new Buffer(this._chunkSize);
-  this._offset = 0;
-  this._closed = false;
-  this._level = level;
-  this._strategy = strategy;
+  var strategy = exports.Z_DEFAULT_STRATEGY
+  if (typeof opts.strategy === 'number') strategy = opts.strategy
 
-  this.once('end', this.close);
+  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
+  this._closed = false
+  this._level = level
+  this._strategy = strategy
+
+  this.once('end', this.close)
 }
 
-util.inherits(Zlib, Transform);
+util.inherits(Zlib, Transform)
 
-Zlib.prototype.params = function(level, strategy, callback) {
+Zlib.prototype.params = function (level, strategy, callback) {
   if (level < exports.Z_MIN_LEVEL ||
-      level > exports.Z_MAX_LEVEL) {
-    throw new RangeError('Invalid compression level: ' + level);
+    level > exports.Z_MAX_LEVEL) {
+    throw new RangeError('Invalid compression level: ' + level)
   }
-  if (strategy != exports.Z_FILTERED &&
-      strategy != exports.Z_HUFFMAN_ONLY &&
-      strategy != exports.Z_RLE &&
-      strategy != exports.Z_FIXED &&
-      strategy != exports.Z_DEFAULT_STRATEGY) {
-    throw new TypeError('Invalid strategy: ' + strategy);
+  if (strategy !== exports.Z_FILTERED &&
+    strategy !== exports.Z_HUFFMAN_ONLY &&
+    strategy !== exports.Z_RLE &&
+    strategy !== exports.Z_FIXED &&
+    strategy !== exports.Z_DEFAULT_STRATEGY) {
+    throw new TypeError('Invalid strategy: ' + strategy)
   }
 
   if (this._level !== level || this._strategy !== strategy) {
-    var self = this;
-    this.flush(binding.Z_SYNC_FLUSH, function() {
-      assert(!self._closed, 'zlib binding closed');
-      self._handle.params(level, strategy);
+    var self = this
+    this.flush(binding.Z_SYNC_FLUSH, function () {
+      assert(!self._closed, 'zlib binding closed')
+      self._handle.params(level, strategy)
       if (!self._hadError) {
-        self._level = level;
-        self._strategy = strategy;
-        if (callback) callback();
+        self._level = level
+        self._strategy = strategy
+        if (callback) callback()
       }
-    });
+    })
   } else {
-    process.nextTick(callback);
+    process.nextTick(callback)
   }
-};
+}
 
-Zlib.prototype.reset = function() {
-  assert(!this._closed, 'zlib binding closed');
-  return this._handle.reset();
-};
+Zlib.prototype.reset = function () {
+  assert(!this._closed, 'zlib binding closed')
+  return this._handle.reset()
+}
 
 // This is the _flush function called by the transform class,
 // internally, when the last chunk has been written.
-Zlib.prototype._flush = function(callback) {
-  this._transform(new Buffer(0), '', callback);
-};
+Zlib.prototype._flush = function (callback) {
+  this._transform(new Buffer(0), '', callback)
+}
 
-Zlib.prototype.flush = function(kind, callback) {
-  var ws = this._writableState;
+Zlib.prototype.flush = function (kind, callback) {
+  var ws = this._writableState
 
   if (typeof kind === 'function' || (kind === undefined && !callback)) {
-    callback = kind;
-    kind = binding.Z_FULL_FLUSH;
+    callback = kind
+    kind = binding.Z_FULL_FLUSH
   }
 
   if (ws.ended) {
-    if (callback)
-      process.nextTick(callback);
+    if (callback) {
+      process.nextTick(callback)
+    }
   } else if (ws.ending) {
-    if (callback)
-      this.once('end', callback);
+    if (callback) {
+      this.once('end', callback)
+    }
   } else if (ws.needDrain) {
     if (callback) {
-      this.once('drain', () => this.flush(kind, callback));
+      var self = this
+      this.once('drain', function () {
+        self.flush(kind, callback)
+      })
     }
   } else {
-    this._flushFlag = kind;
-    this.write(new Buffer(0), '', callback);
+    this._flushFlag = kind
+    this.write(new Buffer(0), '', callback)
   }
-};
-
-Zlib.prototype.close = function(callback) {
-  if (callback)
-    process.nextTick(callback);
+}
 
-  if (this._closed)
-    return;
+Zlib.prototype.close = function (callback) {
+  if (callback) {
+    process.nextTick(callback)
+  }
 
-  this._closed = true;
+  if (this._closed) {
+    return
+  }
+  this._closed = true
 
-  this._handle.close();
+  this._handle.close()
 
-  process.nextTick(emitCloseNT, this);
-};
+  process.nextTick(emitCloseNT, this)
+}
 
-function emitCloseNT(self) {
-  self.emit('close');
+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);
+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 && !(chunk instanceof Buffer))
-    return cb(new Error('invalid input'));
+  if (chunk !== null && !(chunk instanceof Buffer)) {
+    return cb(new Error('invalid input'))
+  }
 
-  if (this._closed)
-    return cb(new Error('zlib binding closed'));
+  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
   // goodness.
-  if (last)
-    flushFlag = binding.Z_FINISH;
-  else {
-    flushFlag = this._flushFlag;
+  if (last) {
+    flushFlag = binding.Z_FINISH
+  } else {
+    flushFlag = this._flushFlag
     // once we've flushed the last of the queue, stop flushing and
     // go back to the normal behavior.
     if (chunk.length >= ws.length) {
-      this._flushFlag = this._opts.flush || binding.Z_NO_FLUSH;
+      this._flushFlag = this._opts.flush || binding.Z_NO_FLUSH
     }
   }
 
-  this._processChunk(chunk, flushFlag, cb);
-};
+  this._processChunk(chunk, flushFlag, cb)
+}
 
-Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
-  var availInBefore = chunk && chunk.length;
-  var availOutBefore = this._chunkSize - this._offset;
-  var inOff = 0;
+Zlib.prototype._processChunk = function (chunk, flushFlag, cb) {
+  var availInBefore = chunk && chunk.length
+  var availOutBefore = this._chunkSize - this._offset
+  var inOff = 0
 
-  var self = this;
+  var self = this
 
-  var async = typeof cb === 'function';
+  var async = typeof cb === 'function'
 
   if (!async) {
-    var buffers = [];
-    var nread = 0;
+    var buffers = []
+    var nread = 0
 
-    var error;
-    this.on('error', function(er) {
-      error = er;
-    });
+    var error
+    this.on('error', function (er) {
+      error = er
+    })
 
-    assert(!this._closed, 'zlib binding closed');
+    assert(!this._closed, 'zlib binding closed')
     do {
       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]));
+        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;
+      throw error
     }
 
     if (nread >= kMaxLength) {
-      this.close();
-      throw new RangeError(kRangeErrorMessage);
+      this.close()
+      throw new RangeError(kRangeErrorMessage)
     }
 
-    var buf = Buffer.concat(buffers, nread);
-    this.close();
+    var buf = Buffer.concat(buffers, nread)
+    this.close()
 
-    return buf;
+    return buf
   }
 
-  assert(!this._closed, 'zlib binding closed');
+  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;
-
-  function callback(availInAfter, availOutAfter) {
-    if (self._hadError)
-      return;
+    chunk, // in
+    inOff, // in_off
+    availInBefore, // in_len
+    this._buffer, // out
+    this._offset, // out_off
+    availOutBefore) // out_len
+
+  req.buffer = chunk
+  req.callback = callback
+
+  function callback (availInAfter, availOutAfter) {
+    if (self._hadError) {
+      return
+    }
 
-    var have = availOutBefore - availOutAfter;
-    assert(have >= 0, 'have should not go down');
+    var have = availOutBefore - availOutAfter
+    assert(have >= 0, 'have should not go down')
 
     if (have > 0) {
-      var out = self._buffer.slice(self._offset, self._offset + have);
-      self._offset += have;
+      var out = self._buffer.slice(self._offset, self._offset + have)
+      self._offset += have
       // serve some output to the consumer.
       if (async) {
-        self.push(out);
+        self.push(out)
       } else {
-        buffers.push(out);
-        nread += out.length;
+        buffers.push(out)
+        nread += out.length
       }
     }
 
     // exhausted the output buffer, or used all the input create a new one.
     if (availOutAfter === 0 || self._offset >= self._chunkSize) {
-      availOutBefore = self._chunkSize;
-      self._offset = 0;
-      self._buffer = new Buffer(self._chunkSize);
+      availOutBefore = self._chunkSize
+      self._offset = 0
+      self._buffer = new Buffer(self._chunkSize)
     }
 
     if (availOutAfter === 0) {
@@ -609,36 +595,37 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
       // Also, update the availInBefore to the availInAfter value,
       // so that if we have to hit it a third (fourth, etc.) time,
       // it'll have the correct byte counts.
-      inOff += (availInBefore - availInAfter);
-      availInBefore = availInAfter;
+      inOff += (availInBefore - availInAfter)
+      availInBefore = availInAfter
 
-      if (!async)
-        return true;
+      if (!async) {
+        return true
+      }
 
       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;
+        chunk,
+        inOff,
+        availInBefore,
+        self._buffer,
+        self._offset,
+        self._chunkSize)
+      newReq.callback = callback // this same function
+      newReq.buffer = chunk
+      return
     }
 
-    if (!async)
-      return false;
-
+    if (!async) {
+      return false
+    }
     // finished with the chunk.
-    cb();
+    cb()
   }
-};
+}
 
-util.inherits(Deflate, Zlib);
-util.inherits(Inflate, Zlib);
-util.inherits(Gzip, Zlib);
-util.inherits(Gunzip, Zlib);
-util.inherits(DeflateRaw, Zlib);
-util.inherits(InflateRaw, Zlib);
-util.inherits(Unzip, Zlib);
+util.inherits(Deflate, Zlib)
+util.inherits(Inflate, Zlib)
+util.inherits(Gzip, Zlib)
+util.inherits(Gunzip, Zlib)
+util.inherits(DeflateRaw, Zlib)
+util.inherits(InflateRaw, Zlib)
+util.inherits(Unzip, Zlib)
diff --git a/test/common.js b/test/common.js
index 6a805c4..20742d5 100644
--- a/test/common.js
+++ b/test/common.js
@@ -1,80 +1,101 @@
-'use strict';
+'use strict'
 
-var path = require('path');
-var fs = require('fs');
+var path = require('path')
+var fs = require('fs')
 
-exports.fixturesDir = path.join(__dirname, 'fixtures');
+exports.fixturesDir = path.join(__dirname, 'fixtures')
 
-var mustCallChecks = [];
+var mustCallChecks = []
 
-function runCallChecks(exitCode) {
-  if (exitCode !== 0) return;
+function runCallChecks (exitCode) {
+  if (exitCode !== 0) return
 
-  var failed = mustCallChecks.filter(function(context) {
-    return context.actual !== context.expected;
-  });
+  var failed = mustCallChecks.filter(function (context) {
+    return context.actual !== context.expected
+  })
 
-  failed.forEach(function(context) {
+  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'));
-  });
+      context.name,
+      context.expected,
+      context.actual)
+    console.log(context.stack.split('\n').slice(2).join('\n'))
+  })
 
-  if (failed.length) process.exit(1);
+  if (failed.length) process.exit(1)
 }
 
-exports.mustCall = function(fn, expected) {
-  if (typeof expected !== 'number') expected = 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);
+  if (mustCallChecks.length === 0) process.on('exit', runCallChecks)
 
-  mustCallChecks.push(context);
+  mustCallChecks.push(context)
 
-  return function() {
-    context.actual++;
-    return fn.apply(this, arguments);
-  };
-};
+  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);
+var testRoot = path.resolve(path.dirname(__filename))
+exports.tmpDirName = 'tmp'
+exports.tmpDir = path.join(testRoot, exports.tmpDirName)
 
-function rimrafSync(p) {
+function rmdirSync (p, originalEr) {
   try {
-    var st = fs.lstatSync(p);
+    fs.rmdirSync(p)
   } catch (e) {
-    if (e.code === 'ENOENT')
-      return;
+    if (e.code === 'ENOTDIR') {
+      throw originalEr
+    }
+    if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
+      fs.readdirSync(p).forEach(function (f) {
+        rimrafSync(path.join(p, f))
+      })
+      fs.rmdirSync(p)
+    }
   }
+}
 
+function rimrafSync (p) {
   try {
-    if (st && st.isDirectory())
-      rmdirSync(p, null);
-    else
-      fs.unlinkSync(p);
+    var st = fs.lstatSync(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);
+    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);
-};
+exports.refreshTmpDir = function () {
+  rimrafSync(exports.tmpDir)
+  fs.mkdirSync(exports.tmpDir)
+}
diff --git a/test/fixtures/person.jpg.gz b/test/fixtures/person.jpg.gz
new file mode 100644
index 0000000..0d3239a
Binary files /dev/null and b/test/fixtures/person.jpg.gz differ
diff --git a/test/ignored/test-zlib-from-concatenated-gzip.js b/test/ignored/test-zlib-from-concatenated-gzip.js
index 52abec1..209ee91 100644
--- a/test/ignored/test-zlib-from-concatenated-gzip.js
+++ b/test/ignored/test-zlib-from-concatenated-gzip.js
@@ -1,18 +1,18 @@
-'use strict';
+'use strict'
 // Test unzipping a gzip file that contains multiple concatenated "members"
 
-const common = require('./common');
-const assert = require('assert');
-const zlib = require('../');
+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');
+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');
-}));
+  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
index dc44bc0..7bebbec 100644
--- a/test/ignored/test-zlib-from-gzip-with-trailing-garbage.js
+++ b/test/ignored/test-zlib-from-gzip-with-trailing-garbage.js
@@ -1,23 +1,23 @@
-'use strict';
+'use strict'
 // test unzipping a gzip file that has trailing garbage
 
-const common = require('./common');
-const assert = require('assert');
-const zlib = require('../');
+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');
+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');
-}));
+  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.
@@ -26,13 +26,13 @@ data = Buffer.concat([
   zlib.gzipSync('def'),
   Buffer([0x1f, 0x8b, 0xff, 0xff]),
   Buffer(10).fill(0)
-]);
+])
 
-assert.throws(() => zlib.gunzipSync(data));
+assert.throws(() => zlib.gunzipSync(data))
 
 zlib.gunzip(data, common.mustCall((err, result) => {
-  assert(err);
-}));
+  assert(err)
+}))
 
 // In this case the trailing junk is too short to be a gzip segment
 // So we ignore it and decompression succeeds.
@@ -40,11 +40,11 @@ data = Buffer.concat([
   zlib.gzipSync('abc'),
   zlib.gzipSync('def'),
   Buffer([0x1f, 0x8b, 0xff, 0xff])
-]);
+])
 
-assert.equal(zlib.gunzipSync(data).toString(), 'abcdef');
+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');
-}));
+  assert.ifError(err)
+  assert.equal(result, 'abcdef', 'result should match original string')
+}))
diff --git a/test/index.js b/test/index.js
deleted file mode 100644
index 3b005e6..0000000
--- a/test/index.js
+++ /dev/null
@@ -1,16 +0,0 @@
-'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 ca2402a..838ed3a 100755
--- a/test/test-zlib-close-after-write.js
+++ b/test/test-zlib-close-after-write.js
@@ -1,18 +1,17 @@
-'use strict';
+/* eslint-env mocha */
+'use strict'
 
-var assert = require('assert');
-var zlib = require('../');
+var zlib = require('../')
 
-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);
-});
+describe('zlib', function () {
+  it('closes after write', function (done) {
+    zlib.gzip('hello', function (err, out) {
+      if (err) throw err
+      var unzip = zlib.createGunzip()
+      unzip.write(out)
+      unzip.close(function () {
+        done()
+      })
+    })
+  })
+})
diff --git a/test/test-zlib-const.js b/test/test-zlib-const.js
index 0f0ff57..ae18642 100644
--- a/test/test-zlib-const.js
+++ b/test/test-zlib-const.js
@@ -1,17 +1,17 @@
 /* eslint-disable strict */
 
-var assert = require('assert');
+var assert = require('assert')
 
-var zlib = require('../');
+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.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.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');
+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 6062d19..dc229a9 100755
--- a/test/test-zlib-convenience-methods.js
+++ b/test/test-zlib-convenience-methods.js
@@ -1,58 +1,71 @@
-'use strict';
-// test convenience methods with and without options supplied
+/* eslint-env mocha */
+'use strict'
 
-var assert = require('assert');
-var zlib = require('../');
+// test convenience methods with and without options supplied
+var assert = require('assert')
+var zlib = require('../')
 
-var hadRun = 0;
+var hadRun = 0
 
-var expect = 'blahblahblahblahblahblah';
+var expect = 'blahblahblahblahblahblah'
 var opts = {
   level: 9,
-  chunkSize: 1024,
-};
-
-[
-  ['gzip', 'gunzip'],
-  ['gzip', 'unzip'],
-  ['deflate', 'inflate'],
-  ['deflateRaw', 'inflateRaw'],
-].forEach(function(method) {
-
-  zlib[method[0]](expect, opts, function(err, result) {
-    zlib[method[1]](result, opts, function(err, result) {
+  chunkSize: 1024
+}
+
+describe('zlib - convenience methods', function () {
+  [
+    ['gzip', 'gunzip'],
+    ['gzip', 'unzip'],
+    ['deflate', 'inflate'],
+    ['deflateRaw', 'inflateRaw']
+  ].forEach(function (method) {
+    it(method.join(':'), function (done) {
+      var finish = function () {
+        hadRun++
+        if (hadRun === 4) {
+          hadRun = 0
+          done()
+        }
+      }
+
+      zlib[method[0]](expect, opts, function (err, result) {
+        if (err) throw err
+
+        zlib[method[1]](result, opts, function (err, result) {
+          if (err) throw err
+
+          assert.equal(result, expect,
+            'Should get original string after ' +
+            method[0] + '/' + method[1] + ' with options.')
+          finish()
+        })
+      })
+
+      zlib[method[0]](expect, function (err, result) {
+        if (err) throw err
+        zlib[method[1]](result, function (err, result) {
+          if (err) throw err
+          assert.equal(result, expect,
+            'Should get original string after ' +
+            method[0] + '/' + method[1] + ' without options.')
+          finish()
+        })
+      })
+
+      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++;
-    });
-  });
+        method[0] + '/' + method[1] + ' with options.')
+      finish()
 
-  zlib[method[0]](expect, function(err, result) {
-    zlib[method[1]](result, function(err, result) {
+      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++;
-    });
-  });
-
-  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');
-});
+        method[0] + '/' + method[1] + ' without options.')
+      finish()
+    })
+  })
+})
diff --git a/test/test-zlib-dictionary-fail.js b/test/test-zlib-dictionary-fail.js
index 7bf64c5..211b6f1 100644
--- a/test/test-zlib-dictionary-fail.js
+++ b/test/test-zlib-dictionary-fail.js
@@ -1,30 +1,35 @@
-'use strict';
-var common = require('./common');
-var assert = require('assert');
-var zlib = require('../');
+/* eslint-env mocha */
+'use strict'
 
-// Should raise an error, not trigger an assertion in src/node_zlib.cc
-(function() {
-  var stream = zlib.createInflate();
+var common = require('./common')
+var zlib = require('../')
 
-  stream.on('error', common.mustCall(function(err) {
-    console.log(err.message);
-    // assert(/Missing dictionary/.test(err.message));
-  }));
+describe('zlib - dictionary fails', function () {
+  it('should fail on missing dictionary', function (done) {
+    // Should raise an error, not trigger an assertion in src/node_zlib.cc
+    var stream = zlib.createInflate()
 
-  // String "test" encoded with dictionary "dict".
-  stream.write(Buffer([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
-})();
+    stream.on('error', common.mustCall(function (err) {
+      console.log(err.message)
+      // assert(/Missing dictionary/.test(err.message))
+      done()
+    }))
 
-// Should raise an error, not trigger an assertion in src/node_zlib.cc
-(function() {
-  var stream = zlib.createInflate({ dictionary: Buffer('fail') });
+    // String "test" encoded with dictionary "dict".
+    stream.write(Buffer([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]))
+  })
 
-  stream.on('error', common.mustCall(function(err) {
-    console.log(err.message);
-    // assert(/Bad dictionary/.test(err.message));
-  }));
+  it('should fail on a bad dictionary', function (done) {
+    // Should raise an error, not trigger an assertion in src/node_zlib.cc
+    var stream = zlib.createInflate({ dictionary: Buffer('fail') })
 
-  // String "test" encoded with dictionary "dict".
-  stream.write(Buffer([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
-})();
+    stream.on('error', common.mustCall(function (err) {
+      console.log(err.message)
+      // assert(/Bad dictionary/.test(err.message))
+      done()
+    }))
+
+    // 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
index 1c791b5..992c399 100644
--- a/test/test-zlib-dictionary.js
+++ b/test/test-zlib-dictionary.js
@@ -1,8 +1,9 @@
-'use strict';
-// test compression/decompression with dictionary
+/* eslint-env mocha */
+'use strict'
 
-const assert = require('assert');
-const zlib = require('../');
+// test compression/decompression with dictionary
+const assert = require('assert')
+const zlib = require('../')
 
 const spdyDict = new Buffer([
   'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-',
@@ -18,71 +19,73 @@ const spdyDict = new Buffer([
   'pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic',
   'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1',
   '.1statusversionurl\0'
-].join(''));
+].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();
+].join('\r\n')
+
+describe('zlib - dictionary', function () {
+  it('basic dictionary', function (done) {
+    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)
+      done()
+    })
+
+    deflate.write(input)
+    deflate.end()
+  })
+
+  it('deflate reset dictionary', function (done) {
+    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)
+      done()
+    })
+
+    deflate.write(input)
+    deflate.flush(function () {
+      deflate.reset()
+      doneReset = true
+      deflate.write(input)
+      deflate.end()
+    })
+  })
+})
diff --git a/test/test-zlib-flush-drain.js b/test/test-zlib-flush-drain.js
index 4f9d450..dc2d717 100644
--- a/test/test-zlib-flush-drain.js
+++ b/test/test-zlib-flush-drain.js
@@ -1,48 +1,55 @@
-'use strict';
+/* eslint-env mocha */
+'use strict'
 
-const assert = require('assert');
-const zlib = require('../');
+var assert = require('assert')
+var zlib = require('../')
 
-const bigData = new Buffer(10240).fill('x');
+var bigData = new Buffer(10240).fill('x')
 
-const opts = {
+var opts = {
   level: 0,
   highWaterMark: 16
-};
+}
 
-const deflater = zlib.createDeflate(opts);
+var 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');
-});
+var flushCount = 0
+var drainCount = 0
+
+describe('zlib - flush drain', function () {
+  it('works', function (done) {
+    var flush = deflater.flush
+    deflater.flush = function (kind, callback) {
+      flushCount++
+      flush.call(this, kind, callback)
+    }
+
+    deflater.write(bigData)
+
+    var ws = deflater._writableState
+    var beforeFlush = ws.needDrain
+    var afterFlush = ws.needDrain
+
+    deflater.flush(function (err) {
+      if (err) throw err
+      afterFlush = ws.needDrain
+
+      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')
+
+      done()
+    })
+
+    deflater.on('drain', function () {
+      drainCount++
+    })
+
+    assert.equal(beforeFlush, true,
+                 'before calling flush the writable stream should need to drain')
+  })
+})
diff --git a/test/test-zlib-flush.js b/test/test-zlib-flush.js
index 17e7bf2..5439a1b 100644
--- a/test/test-zlib-flush.js
+++ b/test/test-zlib-flush.js
@@ -1,36 +1,43 @@
-'use strict';
-var common = require('./common');
-var assert = require('assert');
-var zlib = require('../');
-var path = require('path');
-var fs = require('fs');
+/* eslint-env mocha */
+'use strict'
 
-const file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'));
-const chunkSize = 16;
-const opts = { level: 0 };
-const deflater = zlib.createDeflate(opts);
+var common = require('./common')
+var assert = require('assert')
+var zlib = require('../')
+var path = require('path')
+var fs = require('fs')
 
-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;
+var file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg'))
+var chunkSize = 16
+var opts = { level: 0 }
+var deflater = zlib.createDeflate(opts)
 
-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);
-    });
-  });
-});
+var chunk = file.slice(0, chunkSize)
+var expectedNone = new Buffer([0x78, 0x01])
+var blkhdr = new Buffer([0x00, 0x10, 0x00, 0xef, 0xff])
+var adler32 = new Buffer([0x00, 0x00, 0x00, 0xff, 0xff])
+var expectedFull = Buffer.concat([blkhdr, chunk, adler32])
+var actualNone
+var actualFull
 
-process.once('exit', function() {
-  assert.deepEqual(actualNone, expectedNone);
-  assert.deepEqual(actualFull, expectedFull);
-});
+describe('zlib - flush', function () {
+  it('works', function (done) {
+    deflater.write(chunk, function () {
+      deflater.flush(zlib.Z_NO_FLUSH, function () {
+        actualNone = deflater.read()
+        deflater.flush(function () {
+          var bufs = []
+          var buf
+          // eslint-disable-next-line
+          while (buf = deflater.read()) {}
+          bufs.push(buf)
+          actualFull = Buffer.concat(bufs)
+          assert.deepEqual(actualNone, expectedNone)
+          assert.deepEqual(actualFull, expectedFull)
+
+          done()
+        })
+      })
+    })
+  })
+})
diff --git a/test/test-zlib-from-gzip.js b/test/test-zlib-from-gzip.js
index a2794d7..e7b341f 100644
--- a/test/test-zlib-from-gzip.js
+++ b/test/test-zlib-from-gzip.js
@@ -1,30 +1,36 @@
-'use strict';
+/* eslint-env mocha */
+'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')
 
-var common = require('./common');
-var assert = require('assert');
-var zlib = require('../');
-var path = require('path');
-
-common.refreshTmpDir();
+common.refreshTmpDir()
 
-var gunzip = zlib.createGunzip();
+var gunzip = zlib.createGunzip()
 
-var fs = require('fs');
+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);
+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 + ']');
-  }
-});
+describe('zlib - from gzip', function () {
+  it('works', function (done) {
+    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 + ']')
+      }
+      done()
+    })
+  })
+})
diff --git a/test/test-zlib-from-string.js b/test/test-zlib-from-string.js
index 5ce8fbb..ff51a2f 100755
--- a/test/test-zlib-from-string.js
+++ b/test/test-zlib-from-string.js
@@ -1,57 +1,78 @@
-'use strict';
-// test compressing and uncompressing a string with zlib
+/* eslint-env mocha */
+'use strict'
 
-var assert = require('assert');
-var zlib = require('../');
+// test compressing and uncompressing a string with zlib
+var assert = require('assert')
+var zlib = require('../')
 
 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 ' +
-    '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. ';
+      '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. '
 var expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpm' +
-    'XAKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWLJWkncJG5403HQXAkT3' +
-    'Jw29B9uIEmToMukglZ0vS6ociBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491Lofo' +
-    'AbWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn2t/xjhduTA1N' +
-    'WyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqq' +
-    'qfKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5xzfO/Ll9';
+      'XAKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWLJWkncJG5403HQXAkT3' +
+      'Jw29B9uIEmToMukglZ0vS6ociBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491Lofo' +
+      'AbWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn2t/xjhduTA1N' +
+      'WyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqq' +
+      'qfKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5xzfO/Ll9'
 var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN' +
-    '496pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6QOUpYslaSdwkbnjT' +
-    'cdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYr' +
-    'Lj3Uuh+gBtaHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/G' +
-    'OF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9h' +
-    'N9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2s' +
-    'HnHNzRtagj5AQAA';
+      '496pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6QOUpYslaSdwkbnjT' +
+      'cdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYr' +
+      'Lj3Uuh+gBtaHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/G' +
+      'OF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9h' +
+      'N9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2s' +
+      'HnHNzRtagj5AQAA'
+
+describe('zlib - from string', function () {
+  it('deflate', function (done) {
+    zlib.deflate(inputString, function (err, buffer) {
+      if (err) throw err
+      assert.equal(buffer.toString('base64'), expectedBase64Deflate,
+                   'deflate encoded string should match')
+      done()
+    })
+  })
 
-zlib.deflate(inputString, function(err, buffer) {
-  assert.equal(buffer.toString('base64'), expectedBase64Deflate,
-               'deflate encoded string should match');
-});
+  it('gzip', function (done) {
+    zlib.gzip(inputString, function (err, buffer) {
+      if (err) throw err
 
-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');
-  });
-});
+      // 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) {
+        if (err) throw err
+        assert.equal(gunzipped.toString(), inputString,
+                     'Should get original string after gzip/gunzip')
+        done()
+      })
+    })
+  })
 
-var buffer = new Buffer(expectedBase64Deflate, 'base64');
-zlib.unzip(buffer, function(err, buffer) {
-  assert.equal(buffer.toString(), inputString,
-               'decoded inflated string should match');
-});
+  it('unzip inflated', function (done) {
+    var buffer = new Buffer(expectedBase64Deflate, 'base64')
+    zlib.unzip(buffer, function (err, buffer) {
+      if (err) throw err
+      assert.equal(buffer.toString(), inputString,
+                   'decoded inflated string should match')
+      done()
+    })
+  })
 
-buffer = new Buffer(expectedBase64Gzip, 'base64');
-zlib.unzip(buffer, function(err, buffer) {
-  assert.equal(buffer.toString(), inputString,
-               'decoded gunzipped string should match');
-});
+  it('unzip gunzipped', function (done) {
+    var buffer = new Buffer(expectedBase64Gzip, 'base64')
+    zlib.unzip(buffer, function (err, buffer) {
+      if (err) throw err
+      assert.equal(buffer.toString(), inputString,
+                   'decoded gunzipped string should match')
+      done()
+    })
+  })
+})
diff --git a/test/test-zlib-invalid-input.js b/test/test-zlib-invalid-input.js
index 87a007b..22a4d51 100755
--- a/test/test-zlib-invalid-input.js
+++ b/test/test-zlib-invalid-input.js
@@ -1,44 +1,53 @@
-'use strict';
-// test uncompressing invalid input
+/* eslint-env mocha */
+'use strict'
 
-const assert = require('assert');
-const zlib = require('../');
+// test uncompressing invalid input
+const assert = require('assert')
+const zlib = require('../')
 
-var nonStringInputs = [1, true, {a: 1}, ['a']];
+var nonStringInputs = [1, true, {a: 1}, ['a']]
 
-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);
-    });
-  });
-});
+describe('zlib - invalid input', function () {
+  it('non strings', function (done) {
+    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)
+          done()
+        })
+      })
+    })
+  })
 
-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;
-  });
+  it('unzips', function (done) {
+    // 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 = []
 
-  uz.on('end', function(er) {
-    throw new Error('end event should not be emitted ' + uz.constructor.name);
-  });
+    var finish = function (i) {
+      hadError[i] = true
+      if (hadError.length === 4) {
+        assert.deepEqual(hadError, [true, true, true, true], 'expect 4 errors')
+      }
+    }
+    unzips.forEach(function (uz, i) {
+      uz.on('error', function (er) {
+        finish(i)
+      })
 
-  // 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)
+      })
 
-process.on('exit', function() {
-  assert.deepEqual(hadError, [true, true, true, true], 'expect 4 errors');
-});
+      // this will trigger error event
+      uz.write('this is not valid compressed data.')
+    })
+  })
+})
diff --git a/test/test-zlib-params.js b/test/test-zlib-params.js
index aa3767f..932a82d 100644
--- a/test/test-zlib-params.js
+++ b/test/test-zlib-params.js
@@ -1,34 +1,41 @@
-'use strict';
-var common = require('./common');
-var assert = require('assert');
-var zlib = require('../');
-var path = require('path');
-var fs = require('fs');
+/* eslint-env mocha */
+'use strict'
 
-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 common = require('./common')
+var assert = require('assert')
+var zlib = require('../')
+var path = require('path')
+var fs = require('fs')
 
-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;
+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)
 
-deflater.write(chunk1, function() {
-  deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function() {
-    while (deflater.read());
-    deflater.end(chunk2, function() {
-      var bufs = [], buf;
-      while (buf = deflater.read())
-        bufs.push(buf);
-      actual = Buffer.concat(bufs);
-    });
-  });
-  while (deflater.read());
-});
+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
 
-process.once('exit', function() {
-  assert.deepEqual(actual, expected);
-});
+describe('zlib - params', function () {
+  it('works', function (done) {
+    deflater.write(chunk1, function () {
+      deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function () {
+        while (deflater.read()) {}
+        deflater.end(chunk2, function () {
+          var bufs = []
+          var buf
+          // eslint-disable-next-line
+          while (buf = deflater.read()) {
+            bufs.push(buf)
+          }
+          actual = Buffer.concat(bufs)
+          assert.deepEqual(actual, expected)
+          done()
+        })
+      })
+      while (deflater.read()) {}
+    })
+  })
+})
diff --git a/test/test-zlib-random-byte-pipes.js b/test/test-zlib-random-byte-pipes.js
index 51ad9ea..23aa0f9 100755
--- a/test/test-zlib-random-byte-pipes.js
+++ b/test/test-zlib-random-byte-pipes.js
@@ -1,164 +1,161 @@
-'use strict';
-var common = require('./common');
-var assert = require('assert');
+'use strict'
+var common = require('./common')
+var assert = require('assert')
 
 if (!common.hasCrypto) {
-  console.log('1..0 # Skipped: missing crypto');
-  return;
+  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 zlib = require('../');
+var crypto = require('crypto')
 
+var stream = require('stream')
+var Stream = stream.Stream
+var util = require('util')
+var zlib = require('../')
 
 // emit random bytes, and keep a shasum
-function RandomReadStream(opt) {
-  Stream.call(this);
+function RandomReadStream (opt) {
+  Stream.call(this)
 
-  this.readable = true;
-  this._paused = false;
-  this._processing = false;
+  this.readable = true
+  this._paused = false
+  this._processing = false
 
-  this._hasher = crypto.createHash('sha1');
-  opt = opt || {};
+  this._hasher = crypto.createHash('sha1')
+  opt = opt || {}
 
   // base block size.
-  opt.block = opt.block || 256 * 1024;
+  opt.block = opt.block || 256 * 1024
 
   // total number of bytes to emit
-  opt.total = opt.total || 256 * 1024 * 1024;
-  this._remaining = opt.total;
+  opt.total = opt.total || 256 * 1024 * 1024
+  this._remaining = opt.total
 
   // how variable to make the block sizes
-  opt.jitter = opt.jitter || 1024;
+  opt.jitter = opt.jitter || 1024
 
-  this._opt = opt;
+  this._opt = opt
 
-  this._process = this._process.bind(this);
+  this._process = this._process.bind(this)
 
-  process.nextTick(this._process);
+  process.nextTick(this._process)
 }
 
-util.inherits(RandomReadStream, Stream);
+util.inherits(RandomReadStream, Stream)
 
-RandomReadStream.prototype.pause = function() {
-  this._paused = true;
-  this.emit('pause');
-};
+RandomReadStream.prototype.pause = function () {
+  this._paused = true
+  this.emit('pause')
+}
 
-RandomReadStream.prototype.resume = function() {
-  // console.error("rrs resume");
-  this._paused = false;
-  this.emit('resume');
-  this._process();
-};
+RandomReadStream.prototype.resume = function () {
+  // console.error("rrs resume")
+  this._paused = false
+  this.emit('resume')
+  this._process()
+}
 
-RandomReadStream.prototype._process = function() {
-  if (this._processing) return;
-  if (this._paused) return;
+RandomReadStream.prototype._process = function () {
+  if (this._processing) return
+  if (this._paused) return
 
-  this._processing = true;
+  this._processing = true
 
   if (!this._remaining) {
-    this._hash = this._hasher.digest('hex').toLowerCase().trim();
-    this._processing = false;
+    this._hash = this._hasher.digest('hex').toLowerCase().trim()
+    this._processing = false
 
-    this.emit('end');
-    return;
+    this.emit('end')
+    return
   }
 
   // figure out how many bytes to output
   // if finished, then just emit end.
-  var block = this._opt.block;
-  var jitter = this._opt.jitter;
+  var block = this._opt.block
+  var jitter = this._opt.jitter
   if (jitter) {
-    block += Math.ceil(Math.random() * jitter - (jitter / 2));
+    block += Math.ceil(Math.random() * jitter - (jitter / 2))
   }
-  block = Math.min(block, this._remaining);
-  var buf = new Buffer(block);
+  block = Math.min(block, this._remaining)
+  var buf = new Buffer(block)
   for (var i = 0; i < block; i++) {
-    buf[i] = Math.random() * 256;
+    buf[i] = Math.random() * 256
   }
 
-  this._hasher.update(buf);
+  this._hasher.update(buf)
 
-  this._remaining -= block;
+  this._remaining -= block
 
-  console.error('block=%d\nremain=%d\n', block, this._remaining);
-  this._processing = false;
-
-  this.emit('data', buf);
-  process.nextTick(this._process);
-};
+  console.error('block=%d\nremain=%d\n', block, this._remaining)
+  this._processing = false
 
+  this.emit('data', buf)
+  process.nextTick(this._process)
+}
 
 // a filter that just verifies a shasum
-function HashStream() {
-  Stream.call(this);
+function HashStream () {
+  Stream.call(this)
 
-  this.readable = this.writable = true;
-  this._hasher = crypto.createHash('sha1');
+  this.readable = this.writable = true
+  this._hasher = crypto.createHash('sha1')
 }
 
-util.inherits(HashStream, Stream);
+util.inherits(HashStream, Stream)
 
-HashStream.prototype.write = function(c) {
+HashStream.prototype.write = function (c) {
   // Simulate the way that an fs.ReadStream returns false
   // on *every* write like a jerk, only to resume a
   // moment later.
-  this._hasher.update(c);
-  process.nextTick(this.resume.bind(this));
-  return false;
-};
+  this._hasher.update(c)
+  process.nextTick(this.resume.bind(this))
+  return false
+}
 
-HashStream.prototype.resume = function() {
-  this.emit('resume');
-  process.nextTick(this.emit.bind(this, 'drain'));
-};
+HashStream.prototype.resume = function () {
+  this.emit('resume')
+  process.nextTick(this.emit.bind(this, 'drain'))
+}
 
-HashStream.prototype.end = function(c) {
+HashStream.prototype.end = function (c) {
   if (c) {
-    this.write(c);
+    this.write(c)
   }
-  this._hash = this._hasher.digest('hex').toLowerCase().trim();
-  this.emit('data', this._hash);
-  this.emit('end');
-};
-
+  this._hash = this._hasher.digest('hex').toLowerCase().trim()
+  this.emit('data', this._hash)
+  this.emit('end')
+}
 
-var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 });
-var out = new HashStream();
-var gzip = zlib.createGzip();
-var gunz = zlib.createGunzip();
+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.pipe(gzip).pipe(gunz).pipe(out)
 
-inp.on('data', function(c) {
-  console.error('inp data', c.length);
-});
+inp.on('data', function (c) {
+  console.error('inp data', c.length)
+})
 
-gzip.on('data', function(c) {
-  console.error('gzip 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);
-});
+gunz.on('data', function (c) {
+  console.error('gunz data', c.length)
+})
 
-out.on('data', function(c) {
-  console.error('out 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');
-});
+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');
-});
+process.on('exit', function () {
+  assert(didSomething, 'should have done something')
+})
diff --git a/test/test-zlib-truncated.js b/test/test-zlib-truncated.js
index 5e5c086..f01ac0f 100644
--- a/test/test-zlib-truncated.js
+++ b/test/test-zlib-truncated.js
@@ -1,8 +1,8 @@
-'use strict';
+'use strict'
 // tests zlib streams with truncated compressed input
 
-const assert = require('assert');
-const zlib = require ('zlib');
+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' +
@@ -11,38 +11,38 @@ const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el'
   '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. ';
+  '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);
+].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);
-    });
+    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);
-    });
+    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/);
+    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));
-    });
-  });
-});
+    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
index 827a4bf..1fad3de 100644
--- a/test/test-zlib-write-after-close.js
+++ b/test/test-zlib-write-after-close.js
@@ -1,20 +1,20 @@
-'use strict';
+/* eslint-env mocha */
+'use strict'
 
-var assert = require('assert');
-var zlib = require('../');
+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);
-});
+describe('zlib - write after close', function () {
+  it('works', function (done) {
+    zlib.gzip('hello', function (err, out) {
+      if (err) throw err
+      var unzip = zlib.createGunzip()
+      unzip.close(function () {
+        done()
+      })
+      assert.throws(function () {
+        unzip.write(out)
+      })
+    })
+  })
+})
diff --git a/test/test-zlib-write-after-flush.js b/test/test-zlib-write-after-flush.js
index 4ba2384..a5f95d8 100755
--- a/test/test-zlib-write-after-flush.js
+++ b/test/test-zlib-write-after-flush.js
@@ -1,33 +1,33 @@
-'use strict';
+'use strict'
 
-var assert = require('assert');
-var zlib = require('../');
+var assert = require('assert')
+var zlib = require('../')
 
-var gzip = zlib.createGzip();
-var gunz = zlib.createUnzip();
+var gzip = zlib.createGzip()
+var gunz = zlib.createUnzip()
 
-gzip.pipe(gunz);
+gzip.pipe(gunz)
 
-var output = '';
-var input = 'A line of data\n';
-gunz.setEncoding('utf8');
-gunz.on('data', function(c) {
-  output += c;
-});
+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);
+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);
+  assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH)
 
-  console.log('ok');
-});
+  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);
+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 cc77f70..4a0c80e 100755
--- a/test/test-zlib-zero-byte.js
+++ b/test/test-zlib-zero-byte.js
@@ -1,28 +1,28 @@
-'use strict';
+'use strict'
 
-var assert = require('assert');
+var assert = require('assert')
 
-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();
+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()
 
-process.on('exit', function() {
-  assert.equal(received, 20);
-  assert(ended);
-  assert(finished);
-  console.log('ok');
-});
+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 9e16c64..40ac9ed 100644
--- a/test/test-zlib.js
+++ b/test/test-zlib.js
@@ -1,207 +1,202 @@
-'use strict';
-var common = require('./common');
-var assert = require('assert');
-var zlib = require('../');
-var path = require('path');
-
-var zlibPairs =
-    [[zlib.Deflate, zlib.Inflate],
-     [zlib.Gzip, zlib.Gunzip],
-     [zlib.Deflate, zlib.Unzip],
-     [zlib.Gzip, zlib.Unzip],
-     [zlib.DeflateRaw, zlib.InflateRaw]];
+/* eslint-env mocha */
+'use strict'
+
+var common = require('./common')
+var zlib = require('../')
+var path = require('path')
+
+var zlibPairs = [
+  [zlib.Deflate, zlib.Inflate],
+  [zlib.Gzip, zlib.Gunzip],
+  [zlib.Deflate, zlib.Unzip],
+  [zlib.Gzip, zlib.Unzip],
+  [zlib.DeflateRaw, zlib.InflateRaw]
+]
 
 // how fast to trickle through the slowstream
-var trickle = [128, 1024, 1024 * 1024];
+var trickle = [128, 1024, 1024 * 1024]
 
 // tunable options for zlib classes.
 
 // several different chunk sizes
-var chunkSize = [128, 1024, 1024 * 16, 1024 * 1024];
+var chunkSize = [128, 1024, 1024 * 16, 1024 * 1024]
 
 // this is every possible value.
-var level = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
-var windowBits = [8, 9, 10, 11, 12, 13, 14, 15];
-var memLevel = [1, 2, 3, 4, 5, 6, 7, 8, 9];
-var strategy = [0, 1, 2, 3, 4];
+var level = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+var windowBits = [8, 9, 10, 11, 12, 13, 14, 15]
+var memLevel = [1, 2, 3, 4, 5, 6, 7, 8, 9]
+var strategy = [0, 1, 2, 3, 4]
 
 // it's nice in theory to test every combination, but it
 // takes WAY too long.  Maybe a pummel test could do this?
 if (!process.env.PUMMEL) {
-  trickle = [1024];
-  chunkSize = [1024 * 16];
-  level = [6];
-  memLevel = [8];
-  windowBits = [15];
-  strategy = [0];
+  trickle = [1024]
+  chunkSize = [1024 * 16]
+  level = [6]
+  memLevel = [8]
+  windowBits = [15]
+  strategy = [0]
 }
 
-var fs = require('fs');
+var fs = require('fs')
 
-var testFiles = ['person.jpg', 'elipses.txt', 'empty.txt'];
+var testFiles = ['person.jpg', 'elipses.txt', 'empty.txt']
 
 if (process.env.FAST) {
-  zlibPairs = [[zlib.Gzip, zlib.Unzip]];
-  testFiles = ['person.jpg'];
+  zlibPairs = [[zlib.Gzip, zlib.Unzip]]
+  testFiles = ['person.jpg']
 }
 
-var tests = {};
-testFiles.forEach(function(file) {
-  tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file));
-});
-
-var util = require('util');
-var stream = require('stream');
+var tests = {}
+testFiles.forEach(function (file) {
+  tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file))
+})
 
+var util = require('util')
+var stream = require('stream')
 
 // stream that saves everything
-function BufferStream() {
-  this.chunks = [];
-  this.length = 0;
-  this.writable = true;
-  this.readable = true;
+function BufferStream () {
+  this.chunks = []
+  this.length = 0
+  this.writable = true
+  this.readable = true
 }
 
-util.inherits(BufferStream, stream.Stream);
+util.inherits(BufferStream, stream.Stream)
 
-BufferStream.prototype.write = function(c) {
-  this.chunks.push(c);
-  this.length += c.length;
-  return true;
-};
+BufferStream.prototype.write = function (c) {
+  this.chunks.push(c)
+  this.length += c.length
+  return true
+}
 
-BufferStream.prototype.end = function(c) {
-  if (c) this.write(c);
+BufferStream.prototype.end = function (c) {
+  if (c) this.write(c)
   // flatten
-  var buf = new Buffer(this.length);
-  var i = 0;
-  this.chunks.forEach(function(c) {
-    c.copy(buf, i);
-    i += c.length;
-  });
-  this.emit('data', buf);
-  this.emit('end');
-  return true;
-};
-
-
-function SlowStream(trickle) {
-  this.trickle = trickle;
-  this.offset = 0;
-  this.readable = this.writable = true;
+  var buf = new Buffer(this.length)
+  var i = 0
+  this.chunks.forEach(function (c) {
+    c.copy(buf, i)
+    i += c.length
+  })
+  this.emit('data', buf)
+  this.emit('end')
+  return true
 }
 
-util.inherits(SlowStream, stream.Stream);
-
-SlowStream.prototype.write = function() {
-  throw new Error('not implemented, just call ss.end(chunk)');
-};
-
-SlowStream.prototype.pause = function() {
-  this.paused = true;
-  this.emit('pause');
-};
-
-SlowStream.prototype.resume = function() {
-  var self = this;
-  if (self.ended) return;
-  self.emit('resume');
-  if (!self.chunk) return;
-  self.paused = false;
-  emit();
-  function emit() {
-    if (self.paused) return;
+function SlowStream (trickle) {
+  this.trickle = trickle
+  this.offset = 0
+  this.readable = this.writable = true
+}
+
+util.inherits(SlowStream, stream.Stream)
+
+SlowStream.prototype.write = function () {
+  throw new Error('not implemented, just call ss.end(chunk)')
+}
+
+SlowStream.prototype.pause = function () {
+  this.paused = true
+  this.emit('pause')
+}
+
+SlowStream.prototype.resume = function () {
+  var self = this
+  if (self.ended) return
+  self.emit('resume')
+  if (!self.chunk) return
+  self.paused = false
+  emit()
+  function emit () {
+    if (self.paused) return
     if (self.offset >= self.length) {
-      self.ended = true;
-      return self.emit('end');
+      self.ended = true
+      return self.emit('end')
     }
-    var end = Math.min(self.offset + self.trickle, self.length);
-    var c = self.chunk.slice(self.offset, end);
-    self.offset += c.length;
-    self.emit('data', c);
-    process.nextTick(emit);
+    var end = Math.min(self.offset + self.trickle, self.length)
+    var c = self.chunk.slice(self.offset, end)
+    self.offset += c.length
+    self.emit('data', c)
+    process.nextTick(emit)
   }
-};
+}
 
-SlowStream.prototype.end = function(chunk) {
+SlowStream.prototype.end = function (chunk) {
   // walk over the chunk in blocks.
-  this.chunk = chunk;
-  this.length = chunk.length;
-  this.resume();
-  return this.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 failures = 0;
-var total = 0;
-var done = 0;
-
-Object.keys(tests).forEach(function(file) {
-  var test = tests[file];
-  chunkSize.forEach(function(chunkSize) {
-    trickle.forEach(function(trickle) {
-      windowBits.forEach(function(windowBits) {
-        level.forEach(function(level) {
-          memLevel.forEach(function(memLevel) {
-            strategy.forEach(function(strategy) {
-              zlibPairs.forEach(function(pair) {
-                var Def = pair[0];
-                var Inf = pair[1];
-                var opts = { level: level,
-                  windowBits: windowBits,
-                  memLevel: memLevel,
-                  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');
-});
+
+describe('zlib', function () {
+  Object.keys(tests).forEach(function (file) {
+    var test = tests[file]
+    chunkSize.forEach(function (chunkSize) {
+      trickle.forEach(function (trickle) {
+        windowBits.forEach(function (windowBits) {
+          level.forEach(function (level) {
+            memLevel.forEach(function (memLevel) {
+              strategy.forEach(function (strategy) {
+                zlibPairs.forEach(function (pair) {
+                  var Def = pair[0]
+                  var Inf = pair[1]
+                  var opts = { level: level,
+                               windowBits: windowBits,
+                               memLevel: memLevel,
+                               strategy: strategy }
+
+                  it(Def.name + '.' + Inf.name, function (done) {
+                    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
+                      for (var i = 0; i < Math.max(c.length, test.length); i++) {
+                        if (c[i] !== test[i]) {
+                          ok = false
+                          break
+                        }
+                      }
+
+                      if (ok) {
+                        done()
+                      } else {
+                        var errMsg = [
+                          'not ok ' + msg,
+                          '  ...',
+                          '  testfile: ' + file,
+                          '  type: ' + Def.name + ' -> ' + Inf.name,
+                          '  position: ' + i,
+                          '  options: ' + JSON.stringify(opts),
+                          '  expect: ' + test[i],
+                          '  actual: ' + c[i],
+                          '  chunkSize: ' + chunkSize,
+                          '  ---'
+                        ].join('\n')
+
+                        throw new Error(errMsg)
+                      }
+                    })
+
+                    // the magic happens here.
+                    ss.pipe(def).pipe(inf).pipe(buf)
+                    ss.end(test)
+                  })
+                })
+              }) }) }) }) }) }) // sad stallman is sad.
+  })
+})
diff --git a/test/tmp/person.jpg b/test/tmp/person.jpg
index e69de29..96d4688 100644
Binary files a/test/tmp/person.jpg and b/test/tmp/person.jpg differ

-- 
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