'use strict'; var fs = require('fs'); var path = require('path'); var _ = require('lodash'); var async = require('async'); var pako_utils = require('../lib/zlib/utils'); var pako = require('../index'); // Load fixtures to test // return: { 'filename1': content1, 'filename2': content2, ...} // function loadSamples() { var result = {}; var dir = path.join(__dirname, 'fixtures'); fs.readdirSync(dir).sort().forEach(function (sample) { var filepath = path.join(dir, sample), extname = path.extname(filepath), basename = path.basename(filepath, extname), content = new Uint8Array(fs.readFileSync(filepath)); if (basename[0] === '_') { return; } // skip files with name, started with dash result[basename] = content; }); return result; } // Compare 2 buffers (can be Array, Uint8Array, Buffer). // function cmpBuf(a, b) { if (a.length !== b.length) { return false; } for (var i=0, l=a.length; i 0 && inflate_options.windowBits < 16) { inflate_options.windowBits = 0; } for (name in samples) { data = samples[name]; deflated = is_gzip ? pako.gzip(data, options) : pako.deflate(data, options); // with untyped arrays pako_utils.setTyped(false); inflated = pako.inflate(deflated, inflate_options); pako_utils.setTyped(true); if (!cmpBuf(inflated, data)) { callback('Error in "' + name + '" - inflate result != original'); return; } // with typed arrays inflated = pako.inflate(deflated, inflate_options); if (!cmpBuf(inflated, data)) { callback('Error in "' + name + '" - inflate result != original'); return; } } callback(); } exports.cmpBuf = cmpBuf; exports.testDeflate = testDeflate; exports.testInflate = testInflate; exports.loadSamples = loadSamples;