<commit_before>'use strict';

var test = require('tap').test;
var fs = require('fs');
var path = require('path');
var fstream = require('fstream');
var temp = require('temp');
var dirdiff = require('dirdiff');
var unzip = require('../');

test("uncompressed archive", function (t) {
  var archive = path.join(__dirname, '../testData/uncompressed/archive.zip');

  temp.mkdir('node-unzip-', function (err, dirPath) {
    if (err) {
      t.fail(err);
    }
    var unzipParser = unzip.Parse();
    unzipParser.on('error', function(err) {
      return t.fail(err);
    });

    var writer = fstream.Writer(dirPath);
    writer.on('error', function(err) {
      t.fail(err);
    });
    writer.on('close', testExtractionResults);

    fs.createReadStream(archive).pipe(unzipParser).pipe(writer);

    function testExtractionResults() {
      dirdiff(path.join(__dirname, '../testData/uncompressed/inflated'), dirPath, {
        fileContents: true
      }, function (err, diffs) {
        if (err) {
          return t.fail(err);
        }
        t.equal(0, diffs.length, 'archive directory incorrect');
        return t.end();
      });
    }
  });
});

test("compressed archive", function (t) {
  var archive = path.join(__dirname, '../testData/compressed/archive.zip');

  temp.mkdir('node-unzip-', function (err, dirPath) {
    if (err) {
      t.fail(err);
    }
    var unzipParser = unzip.Parse();
    unzipParser.on('error', function(err) {
      return t.fail(err);
    });

    var writer = fstream.Writer(dirPath);
    writer.on('error', function(err) {
      t.fail(err);
    });
    writer.on('close', testExtractionResults);

    fs.createReadStream(archive).pipe(unzipParser).pipe(writer);

    function testExtractionResults() {
      dirdiff(path.join(__dirname, '../testData/compressed/inflated'), dirPath, {
        fileContents: true
      }, function (err, diffs) {
        if (err) {
          return t.fail(err);
        }
        t.equal(0, diffs.length, 'archive directory incorrect');
        return t.end();
      });
    }
  });
});<commit_msg>Update tests for Extract api<commit_after>'use strict';

var test = require('tap').test;
var fs = require('fs');
var path = require('path');
var fstream = require('fstream');
var temp = require('temp');
var dirdiff = require('dirdiff');
var unzip = require('../');

test("uncompressed archive", function (t) {
  var archive = path.join(__dirname, '../testData/uncompressed/archive.zip');

  temp.mkdir('node-unzip-', function (err, dirPath) {
    if (err) {
      t.fail(err);
    }
    var unzipExtracter = unzip.Extract({ path: dirPath });
    unzipExtracter.on('error', function(err) {
      return t.fail(err);
    });
    unzipExtracter.on('end', testExtractionResults);

    fs.createReadStream(archive).pipe(unzipExtracter);

    function testExtractionResults() {
      dirdiff(path.join(__dirname, '../testData/uncompressed/inflated'), dirPath, {
        fileContents: true
      }, function (err, diffs) {
        if (err) {
          return t.fail(err);
        }
        t.equal(0, diffs.length, 'archive directory incorrect');
        return t.end();
      });
    }
  });
});

test("compressed archive", function (t) {
  var archive = path.join(__dirname, '../testData/compressed/archive.zip');

  temp.mkdir('node-unzip-', function (err, dirPath) {
    if (err) {
      t.fail(err);
    }
    var unzipExtracter = unzip.Extract({ path: dirPath });
    unzipExtracter.on('error', function(err) {
      return t.fail(err);
    });
    unzipExtracter.on('end', testExtractionResults);

    fs.createReadStream(archive).pipe(unzipExtracter);

    function testExtractionResults() {
      dirdiff(path.join(__dirname, '../testData/compressed/inflated'), dirPath, {
        fileContents: true
      }, function (err, diffs) {
        if (err) {
          return t.fail(err);
        }
        t.equal(0, diffs.length, 'archive directory incorrect');
        return t.end();
      });
    }
  });
});
{'fraction_non_alphanumeric': 0.16997736987679155, 'fraction_numerical': 0.0010057832537088258, 'mean_word_length': 2.934718100890208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6228498', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1270, 'n_words': 250}