JavaScript Benchmarking various node.js unzip libraries using benchmark.js

I'm trying to write a benchmark, using benchmark.js, for some popular node.js unzip libs, mainly adm-zip, yauzl & unzip. However, I'm not sure if I've written the benchmark code correctly, because I keep getting Error: UNKNOWN, open 'file-<unzip-lib>.zip' errors for the libs that unzip asynchronously.

I created 3 copies of a sample zip file file-<unzip-lib>.zip, one for each library to work on.

Here's the code:

"use strict";

var fs = require("fs");

var Benchmark = require("benchmark");

var AdmZip = require("adm-zip"),
    yauzl = require("yauzl"),
    unzip = require("unzip");

var suite = new Benchmark.Suite;
var entryFile = "file.xml",
    targetDir = "./unzipped/";

suite
    .add("Adm-Zip#extractEntryTo", function() {
        var zip = new AdmZip("./file-adm-zip.zip");
        zip.extractEntryTo(entryFile, targetDir + "adm-zip/", /*maintainEntryPath*/false, /*overwrite*/true);
    })
    .add("YAUZL#open", function() {
        yauzl.open("./file-yauzl.zip", function(err, zip) {
            if (err) throw err;
            zip.on("entry", function(entry) {
                if (entryFile === (entry.fileName)) {
                    zip.openReadStream(entry, function(err, readStream) {
                        if (err) throw err;
                        // ensure parent directory exists, and then:
                        readStream.pipe(fs.createWriteStream(targetDir + "yauzl/" + entry.fileName));
                    });
                }
            });
            zip.once("end", function() {
                console.log("[YAUZL] Closing zip");
                zip.close();
            });
        });
    })
    .add("UNZIP#Parse", function() {
        fs.createReadStream("./file-unzip.zip")
            .pipe(unzip.Parse())
            .on("entry", function (entry) {
                var fileName = entry.path;
                if (fileName === entryFile) {
                    entry.pipe(fs.createWriteStream(targetDir + "unzip/" + fileName));
                } else {
                    entry.autodrain();
                }
            })
            .on("close", function() {
                console.log("[UNZIP] Closing zip");
            });
    })
    // add listeners
    .on("cycle", function(event) {
        console.log(String(event.target));
    })
    .on("complete", function() {
        console.log("Fastest is " + this.filter("fastest").pluck("name"));
    })
    // run async
    .run({ "async": true });

Is it failing because the streams haven't been closed properly? I'm not entirely sure this is the case, because I do see, for example, the [YAUZL] Closing zip message being displayed each time the yauzl test is run.

Here's a sample run:

$ node benchmark-unzippers.js 
Adm-Zip#extractEntryTo x 2.56 ops/sec ±1.62% (11 runs sampled)
[YAUZL] Closing zip
[YAUZL] Closing zip
[YAUZL] Closing zip
[YAUZL] Closing zip

~/benchmark-unzippers.js:23
            if (err) throw err;
                           ^
Error: UNKNOWN, open 'file-yauzl.zip'

Not entirely sure what's going on here.

Answer:1

I hope this question is not confusing or too complex. but here we go: I'm creating a custom google map that renders some US states as polygon overlays with the "google.map.Polygon' method. Everything ...

I hope this question is not confusing or too complex. but here we go: I'm creating a custom google map that renders some US states as polygon overlays with the "google.map.Polygon' method. Everything ...

I'm looking for a way to, from a backbone collection, retrieve some kind of array of one specific attribute. var SomeModel = Backbone.Model.extend({ defaults: function() { return { ...

I'm looking for a way to, from a backbone collection, retrieve some kind of array of one specific attribute. var SomeModel = Backbone.Model.extend({ defaults: function() { return { ...

To see the result, open console in Google Chrome, do the following: obj = new Boolean(false) "obj && true: " + (obj && true) "obj || true: " + (obj || false) and: (obj && ...

To see the result, open console in Google Chrome, do the following: obj = new Boolean(false) "obj && true: " + (obj && true) "obj || true: " + (obj || false) and: (obj && ...

  1. javascript snake
  2. javascript foreach
  3. javascript map
  4. javascript for loop
  5. javascript array
  6. javascript substring
  7. javascript switch
  8. javascript reduce

I have the following HTML: <ul> <li></li> <li></li> <li></li> </ul> and the following jQuery code: $('> ul li', body).each(function() { $('...

I have the following HTML: <ul> <li></li> <li></li> <li></li> </ul> and the following jQuery code: $('> ul li', body).each(function() { $('...

  1. jquery swap tag
  2. jquery switch tag