diff --git a/package.json b/package.json index fc51933..1df94bc 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "sideEffects": false, "scripts": { "build-package": "rollup -c", + "build_fixtures": "node support/build_fixtures.js", "test": "vitest --run", "lint": "eslint", "prepare": "husky" diff --git a/support/build_fixtures.js b/support/build_fixtures.js new file mode 100644 index 0000000..76fcb99 --- /dev/null +++ b/support/build_fixtures.js @@ -0,0 +1,78 @@ +#!/usr/bin/env node + +'use strict'; + +// node.js switched to chromium zlib implementation in version v12.17.0, +// which generates slightly different fixtures. +// https://github.com/nodejs/node/pull/31201 +// +// so we create fixtures generated by older node.js versions + +const ver = process.version.match(/^v(\d+)\.(\d+)\.\d+$/); + +if (!(+ver[1] < 12 || +ver[1] === 12 && +ver[2] <= 16)) { + throw new Error('Please use node.js <= 12.16.x to generate these fixtures'); +} + +const fs = require('fs'); +const path = require('path'); +const zlib = require('zlib'); + +const sample = fs.readFileSync(path.join(__dirname, '../test/fixtures/samples/lorem_en_100k.txt')); + +let dirname = path.join(__dirname, '../test/fixtures/binary_compare'); +if (!fs.existsSync(dirname)) fs.mkdirSync(dirname); + + +function createSample(method, options, filename) { + let file = path.join(dirname, filename); + let data = zlib[method](sample, options); + fs.writeFileSync(file, zlib[method](sample, options)); + console.log(file, data.length); +} + + +createSample('deflateSync', {}, 'deflate.bin'); +createSample('deflateRawSync', {}, 'deflateRaw.bin'); +createSample('gzipSync', {}, 'gzip.bin'); +createSample('deflateSync', { level: 9 }, 'deflate_level=9.bin'); +createSample('deflateSync', { level: 8 }, 'deflate_level=8.bin'); +createSample('deflateSync', { level: 7 }, 'deflate_level=7.bin'); +createSample('deflateSync', { level: 6 }, 'deflate_level=6.bin'); +createSample('deflateSync', { level: 5 }, 'deflate_level=5.bin'); +createSample('deflateSync', { level: 4 }, 'deflate_level=4.bin'); +createSample('deflateSync', { level: 3 }, 'deflate_level=3.bin'); +createSample('deflateSync', { level: 2 }, 'deflate_level=2.bin'); +createSample('deflateSync', { level: 1 }, 'deflate_level=1.bin'); +createSample('deflateSync', { level: -1 }, 'deflate_level=-1.bin'); +createSample('deflateSync', { windowBits: 15 }, 'deflate_windowBits=15.bin'); +createSample('deflateSync', { windowBits: 14 }, 'deflate_windowBits=14.bin'); +createSample('deflateSync', { windowBits: 13 }, 'deflate_windowBits=13.bin'); +createSample('deflateSync', { windowBits: 12 }, 'deflate_windowBits=12.bin'); +createSample('deflateSync', { windowBits: 11 }, 'deflate_windowBits=11.bin'); +createSample('deflateSync', { windowBits: 10 }, 'deflate_windowBits=10.bin'); +createSample('deflateSync', { windowBits: 9 }, 'deflate_windowBits=9.bin'); +createSample('deflateSync', { windowBits: 8 }, 'deflate_windowBits=8.bin'); +createSample('deflateRawSync', { windowBits: 15 }, 'deflateRaw_windowBits=15.bin'); +createSample('deflateSync', { memLevel: 9 }, 'deflate_memLevel=9.bin'); +createSample('deflateSync', { memLevel: 8 }, 'deflate_memLevel=8.bin'); +createSample('deflateSync', { memLevel: 7 }, 'deflate_memLevel=7.bin'); +createSample('deflateSync', { memLevel: 6 }, 'deflate_memLevel=6.bin'); +createSample('deflateSync', { memLevel: 5 }, 'deflate_memLevel=5.bin'); +createSample('deflateSync', { memLevel: 4 }, 'deflate_memLevel=4.bin'); +createSample('deflateSync', { memLevel: 3 }, 'deflate_memLevel=3.bin'); +createSample('deflateSync', { memLevel: 2 }, 'deflate_memLevel=2.bin'); +createSample('deflateSync', { memLevel: 1 }, 'deflate_memLevel=1.bin'); +createSample('deflateSync', { strategy: 0 }, 'deflate_strategy=0.bin'); +createSample('deflateSync', { strategy: 1 }, 'deflate_strategy=1.bin'); +createSample('deflateSync', { strategy: 2 }, 'deflate_strategy=2.bin'); +createSample('deflateSync', { strategy: 3 }, 'deflate_strategy=3.bin'); +createSample('deflateSync', { strategy: 4 }, 'deflate_strategy=4.bin'); +createSample('deflateRawSync', { level: 4 }, 'deflateRaw_level=4.bin'); +createSample('deflateRawSync', { level: 1 }, 'deflateRaw_level=1.bin'); + +const dict = Buffer.from('abcdefghijklmnoprstuvwxyz'); +createSample('deflateSync', { dictionary: dict }, 'deflate_dictionary=trivial.bin'); + +const spdyDict = fs.readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'spdy_dict.txt')); +createSample('deflateSync', { dictionary: spdyDict }, 'deflate_dictionary=spdy.bin'); diff --git a/test/binary_compare.js b/test/binary_compare.js new file mode 100644 index 0000000..9f46684 --- /dev/null +++ b/test/binary_compare.js @@ -0,0 +1,199 @@ +'use strict'; + +import { assert, describe, it } from 'vitest'; +import fs from 'fs'; +import path from 'path'; +import * as pako from '../lib/main'; +import { loadSamples } from './helpers'; + +const sample = loadSamples().lorem_en_100k; + + +// Helper used to compare pako deflate using various options +// with reference values from old node.js zlib. +// +// node.js switched to chromium zlib implementation in version v12.17.0, +// which generates slightly different fixtures. +// https://github.com/nodejs/node/pull/31201 +// +// So we use fixtures generated by node.js versions below v12.17.0. +// +function testSample(pako_method, sample, options, filename) { + const dir = path.join(__dirname, 'fixtures', 'binary_compare'); + + const pako_result = pako_method(sample, options); + const zlib_result = fs.readFileSync(path.join(dir, filename)); + + // One more hack: gzip header contains OS code, that can vary. + // Override OS code if requested. For simplicity, we assume it on fixed + // position (= no additional gzip headers used) + if (options.ignore_os) zlib_result[9] = pako_result[9]; + + assert.deepStrictEqual(pako_result, new Uint8Array(zlib_result)); +} + + +describe('Deflate defaults', () => { + + it('deflate, no options', () => { + testSample(pako.deflate, sample, {}, 'deflate.bin'); + }); + + it('deflate raw, no options', () => { + testSample(pako.deflateRaw, sample, {}, 'deflateRaw.bin'); + }); + + // OS code in header can vary. Use hack flag to ignore it. + it('gzip, no options', () => { + testSample(pako.gzip, sample, { ignore_os: true }, 'gzip.bin'); + }); +}); + + +describe('Deflate levels', () => { + + it('level 9', () => { + testSample(pako.deflate, sample, { level: 9 }, 'deflate_level=9.bin'); + }); + it('level 8', () => { + testSample(pako.deflate, sample, { level: 8 }, 'deflate_level=8.bin'); + }); + it('level 7', () => { + testSample(pako.deflate, sample, { level: 7 }, 'deflate_level=7.bin'); + }); + it('level 6', () => { + testSample(pako.deflate, sample, { level: 6 }, 'deflate_level=6.bin'); + }); + it('level 5', () => { + testSample(pako.deflate, sample, { level: 5 }, 'deflate_level=5.bin'); + }); + it('level 4', () => { + testSample(pako.deflate, sample, { level: 4 }, 'deflate_level=4.bin'); + }); + it('level 3', () => { + testSample(pako.deflate, sample, { level: 3 }, 'deflate_level=3.bin'); + }); + it('level 2', () => { + testSample(pako.deflate, sample, { level: 2 }, 'deflate_level=2.bin'); + }); + it('level 1', () => { + testSample(pako.deflate, sample, { level: 1 }, 'deflate_level=1.bin'); + }); + it('level -1 (implicit default)', () => { + testSample(pako.deflate, sample, { level: -1 }, 'deflate_level=-1.bin'); + }); +}); + + +describe('Deflate windowBits', () => { + + it('windowBits 15', () => { + testSample(pako.deflate, sample, { windowBits: 15 }, 'deflate_windowBits=15.bin'); + }); + it('windowBits 14', () => { + testSample(pako.deflate, sample, { windowBits: 14 }, 'deflate_windowBits=14.bin'); + }); + it('windowBits 13', () => { + testSample(pako.deflate, sample, { windowBits: 13 }, 'deflate_windowBits=13.bin'); + }); + it('windowBits 12', () => { + testSample(pako.deflate, sample, { windowBits: 12 }, 'deflate_windowBits=12.bin'); + }); + it('windowBits 11', () => { + testSample(pako.deflate, sample, { windowBits: 11 }, 'deflate_windowBits=11.bin'); + }); + it('windowBits 10', () => { + testSample(pako.deflate, sample, { windowBits: 10 }, 'deflate_windowBits=10.bin'); + }); + it('windowBits 9', () => { + testSample(pako.deflate, sample, { windowBits: 9 }, 'deflate_windowBits=9.bin'); + }); + it('windowBits 8', () => { + testSample(pako.deflate, sample, { windowBits: 8 }, 'deflate_windowBits=8.bin'); + }); + it('windowBits -15 (implicit raw)', () => { + testSample(pako.deflate, sample, { windowBits: -15 }, 'deflateRaw_windowBits=15.bin'); + }); + +}); + + +describe('Deflate memLevel', () => { + + it('memLevel 9', () => { + testSample(pako.deflate, sample, { memLevel: 9 }, 'deflate_memLevel=9.bin'); + }); + it('memLevel 8', () => { + testSample(pako.deflate, sample, { memLevel: 8 }, 'deflate_memLevel=8.bin'); + }); + it('memLevel 7', () => { + testSample(pako.deflate, sample, { memLevel: 7 }, 'deflate_memLevel=7.bin'); + }); + it('memLevel 6', () => { + testSample(pako.deflate, sample, { memLevel: 6 }, 'deflate_memLevel=6.bin'); + }); + it('memLevel 5', () => { + testSample(pako.deflate, sample, { memLevel: 5 }, 'deflate_memLevel=5.bin'); + }); + it('memLevel 4', () => { + testSample(pako.deflate, sample, { memLevel: 4 }, 'deflate_memLevel=4.bin'); + }); + it('memLevel 3', () => { + testSample(pako.deflate, sample, { memLevel: 3 }, 'deflate_memLevel=3.bin'); + }); + it('memLevel 2', () => { + testSample(pako.deflate, sample, { memLevel: 2 }, 'deflate_memLevel=2.bin'); + }); + it('memLevel 1', () => { + testSample(pako.deflate, sample, { memLevel: 1 }, 'deflate_memLevel=1.bin'); + }); + +}); + + +describe('Deflate strategy', () => { + + it('Z_DEFAULT_STRATEGY', () => { + testSample(pako.deflate, sample, { strategy: 0 }, 'deflate_strategy=0.bin'); + }); + it('Z_FILTERED', () => { + testSample(pako.deflate, sample, { strategy: 1 }, 'deflate_strategy=1.bin'); + }); + it('Z_HUFFMAN_ONLY', () => { + testSample(pako.deflate, sample, { strategy: 2 }, 'deflate_strategy=2.bin'); + }); + it('Z_RLE', () => { + testSample(pako.deflate, sample, { strategy: 3 }, 'deflate_strategy=3.bin'); + }); + it('Z_FIXED', () => { + testSample(pako.deflate, sample, { strategy: 4 }, 'deflate_strategy=4.bin'); + }); + +}); + + +describe('Deflate RAW', () => { + // Since difference is only in wrapper, test for store/fast/slow methods are enough + it('level 4', () => { + testSample(pako.deflateRaw, sample, { level: 4 }, 'deflateRaw_level=4.bin'); + }); + it('level 1', () => { + testSample(pako.deflateRaw, sample, { level: 1 }, 'deflateRaw_level=1.bin'); + }); + +}); + + +describe('Deflate dictionary', () => { + + it('trivial dictionary', () => { + const dict = Buffer.from('abcdefghijklmnoprstuvwxyz'); + testSample(pako.deflate, sample, { dictionary: dict }, 'deflate_dictionary=trivial.bin'); + }); + + it('spdy dictionary', () => { + const spdyDict = require('fs').readFileSync(require('path').join(__dirname, 'fixtures', 'spdy_dict.txt')); + + testSample(pako.deflate, sample, { dictionary: spdyDict }, 'deflate_dictionary=spdy.bin'); + }); +}); diff --git a/test/deflate.js b/test/deflate.js index 5086e1b..1378bb9 100644 --- a/test/deflate.js +++ b/test/deflate.js @@ -9,179 +9,8 @@ import fs from 'fs'; import path from 'path'; import b from 'buffer-from'; -var testSamples = helpers.testSamples; -var samples = helpers.loadSamples(); - -describe('Deflate defaults', function () { - - it('deflate, no options', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, {}); - }); - - it('deflate raw, no options', function () { - testSamples(zlib.deflateRawSync, pako.deflateRaw, samples, {}); - }); - - // OS code in header can vary. Use hack flag to ignore it. - it('gzip, no options', function () { - testSamples(zlib.gzipSync, pako.gzip, samples, { ignore_os: true }); - }); -}); - - -describe('Deflate levels', function () { - - it('level 9', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 9 }); - }); - it('level 8', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 8 }); - }); - it('level 7', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 7 }); - }); - it('level 6', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 6 }); - }); - it('level 5', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 5 }); - }); - it('level 4', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 4 }); - }); - it('level 3', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 3 }); - }); - it('level 2', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 2 }); - }); - it('level 1', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 1 }); - }); - it.skip('level 0', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: 0 }); - }); - it('level -1 (implicit default)', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { level: -1 }); - }); -}); - - -describe('Deflate windowBits', function () { - - it('windowBits 15', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 15 }); - }); - it('windowBits 14', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 14 }); - }); - it('windowBits 13', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 13 }); - }); - it('windowBits 12', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 12 }); - }); - it('windowBits 11', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 11 }); - }); - it('windowBits 10', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 10 }); - }); - it('windowBits 9', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 9 }); - }); - it('windowBits 8', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { windowBits: 8 }); - }); - it('windowBits -15 (implicit raw)', function () { - testSamples(zlib.deflateRawSync, pako.deflate, samples, { windowBits: -15 }); - }); - -}); - - -describe('Deflate memLevel', function () { - - it('memLevel 9', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 9 }); - }); - it('memLevel 8', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 8 }); - }); - it('memLevel 7', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 7 }); - }); - it('memLevel 6', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 6 }); - }); - it('memLevel 5', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 5 }); - }); - it('memLevel 4', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 4 }); - }); - it('memLevel 3', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 3 }); - }); - it('memLevel 2', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 2 }); - }); - it('memLevel 1', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { memLevel: 1 }); - }); - -}); - - -describe('Deflate strategy', function () { - - it('Z_DEFAULT_STRATEGY', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { strategy: 0 }); - }); - it('Z_FILTERED', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { strategy: 1 }); - }); - it('Z_HUFFMAN_ONLY', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { strategy: 2 }); - }); - it('Z_RLE', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { strategy: 3 }); - }); - it('Z_FIXED', function () { - testSamples(zlib.deflateSync, pako.deflate, samples, { strategy: 4 }); - }); - -}); - - -describe('Deflate RAW', function () { - // Since difference is only in rwapper, test for store/fast/slow methods are enough - it('level 4', function () { - testSamples(zlib.deflateRawSync, pako.deflateRaw, samples, { level: 4 }); - }); - it('level 1', function () { - testSamples(zlib.deflateRawSync, pako.deflateRaw, samples, { level: 1 }); - }); - it.skip('level 0', function () { - testSamples(zlib.deflateRawSync, pako.deflateRaw, samples, { level: 0 }); - }); - -}); - - describe('Deflate dictionary', function () { - it('trivial dictionary', function () { - var dict = b('abcdefghijklmnoprstuvwxyz'); - testSamples(zlib.deflateSync, pako.deflate, samples, { dictionary: dict }); - }); - - it('spdy dictionary', function () { - var spdyDict = require('fs').readFileSync(require('path').join(__dirname, 'fixtures', 'spdy_dict.txt')); - - testSamples(zlib.deflateSync, pako.deflate, samples, { dictionary: spdyDict }); - }); - it('handles multiple pushes', function () { var dict = b('abcd'); var deflate = new pako.Deflate({ dictionary: dict }); diff --git a/test/fixtures/binary_compare/deflate.bin b/test/fixtures/binary_compare/deflate.bin new file mode 100644 index 0000000..c3df954 Binary files /dev/null and b/test/fixtures/binary_compare/deflate.bin differ diff --git a/test/fixtures/binary_compare/deflateRaw.bin b/test/fixtures/binary_compare/deflateRaw.bin new file mode 100644 index 0000000..49a88fc Binary files /dev/null and b/test/fixtures/binary_compare/deflateRaw.bin differ diff --git a/test/fixtures/binary_compare/deflateRaw_level=1.bin b/test/fixtures/binary_compare/deflateRaw_level=1.bin new file mode 100644 index 0000000..c51f71b Binary files /dev/null and b/test/fixtures/binary_compare/deflateRaw_level=1.bin differ diff --git a/test/fixtures/binary_compare/deflateRaw_level=4.bin b/test/fixtures/binary_compare/deflateRaw_level=4.bin new file mode 100644 index 0000000..fb9d9aa Binary files /dev/null and b/test/fixtures/binary_compare/deflateRaw_level=4.bin differ diff --git a/test/fixtures/binary_compare/deflateRaw_windowBits=15.bin b/test/fixtures/binary_compare/deflateRaw_windowBits=15.bin new file mode 100644 index 0000000..49a88fc Binary files /dev/null and b/test/fixtures/binary_compare/deflateRaw_windowBits=15.bin differ diff --git a/test/fixtures/binary_compare/deflate_dictionary=spdy.bin b/test/fixtures/binary_compare/deflate_dictionary=spdy.bin new file mode 100644 index 0000000..2ca5edd Binary files /dev/null and b/test/fixtures/binary_compare/deflate_dictionary=spdy.bin differ diff --git a/test/fixtures/binary_compare/deflate_dictionary=trivial.bin b/test/fixtures/binary_compare/deflate_dictionary=trivial.bin new file mode 100644 index 0000000..3957e6b Binary files /dev/null and b/test/fixtures/binary_compare/deflate_dictionary=trivial.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=-1.bin b/test/fixtures/binary_compare/deflate_level=-1.bin new file mode 100644 index 0000000..c3df954 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=-1.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=1.bin b/test/fixtures/binary_compare/deflate_level=1.bin new file mode 100644 index 0000000..0f9b4b0 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=1.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=2.bin b/test/fixtures/binary_compare/deflate_level=2.bin new file mode 100644 index 0000000..4da75f3 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=2.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=3.bin b/test/fixtures/binary_compare/deflate_level=3.bin new file mode 100644 index 0000000..3e6c1c4 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=3.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=4.bin b/test/fixtures/binary_compare/deflate_level=4.bin new file mode 100644 index 0000000..d8b1038 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=4.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=5.bin b/test/fixtures/binary_compare/deflate_level=5.bin new file mode 100644 index 0000000..29fe427 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=5.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=6.bin b/test/fixtures/binary_compare/deflate_level=6.bin new file mode 100644 index 0000000..c3df954 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=6.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=7.bin b/test/fixtures/binary_compare/deflate_level=7.bin new file mode 100644 index 0000000..480ca40 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=7.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=8.bin b/test/fixtures/binary_compare/deflate_level=8.bin new file mode 100644 index 0000000..c5c7446 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=8.bin differ diff --git a/test/fixtures/binary_compare/deflate_level=9.bin b/test/fixtures/binary_compare/deflate_level=9.bin new file mode 100644 index 0000000..c5c7446 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_level=9.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=1.bin b/test/fixtures/binary_compare/deflate_memLevel=1.bin new file mode 100644 index 0000000..01bf9aa Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=1.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=2.bin b/test/fixtures/binary_compare/deflate_memLevel=2.bin new file mode 100644 index 0000000..88d5974 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=2.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=3.bin b/test/fixtures/binary_compare/deflate_memLevel=3.bin new file mode 100644 index 0000000..aa1030d Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=3.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=4.bin b/test/fixtures/binary_compare/deflate_memLevel=4.bin new file mode 100644 index 0000000..9ed20b3 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=4.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=5.bin b/test/fixtures/binary_compare/deflate_memLevel=5.bin new file mode 100644 index 0000000..4e30aaa Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=5.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=6.bin b/test/fixtures/binary_compare/deflate_memLevel=6.bin new file mode 100644 index 0000000..e2f1fb6 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=6.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=7.bin b/test/fixtures/binary_compare/deflate_memLevel=7.bin new file mode 100644 index 0000000..d81730e Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=7.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=8.bin b/test/fixtures/binary_compare/deflate_memLevel=8.bin new file mode 100644 index 0000000..c3df954 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=8.bin differ diff --git a/test/fixtures/binary_compare/deflate_memLevel=9.bin b/test/fixtures/binary_compare/deflate_memLevel=9.bin new file mode 100644 index 0000000..b41d496 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_memLevel=9.bin differ diff --git a/test/fixtures/binary_compare/deflate_strategy=0.bin b/test/fixtures/binary_compare/deflate_strategy=0.bin new file mode 100644 index 0000000..c3df954 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_strategy=0.bin differ diff --git a/test/fixtures/binary_compare/deflate_strategy=1.bin b/test/fixtures/binary_compare/deflate_strategy=1.bin new file mode 100644 index 0000000..a5cb7b1 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_strategy=1.bin differ diff --git a/test/fixtures/binary_compare/deflate_strategy=2.bin b/test/fixtures/binary_compare/deflate_strategy=2.bin new file mode 100644 index 0000000..b82c36f Binary files /dev/null and b/test/fixtures/binary_compare/deflate_strategy=2.bin differ diff --git a/test/fixtures/binary_compare/deflate_strategy=3.bin b/test/fixtures/binary_compare/deflate_strategy=3.bin new file mode 100644 index 0000000..72c13b6 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_strategy=3.bin differ diff --git a/test/fixtures/binary_compare/deflate_strategy=4.bin b/test/fixtures/binary_compare/deflate_strategy=4.bin new file mode 100644 index 0000000..26124c0 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_strategy=4.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=10.bin b/test/fixtures/binary_compare/deflate_windowBits=10.bin new file mode 100644 index 0000000..21a2d2f Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=10.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=11.bin b/test/fixtures/binary_compare/deflate_windowBits=11.bin new file mode 100644 index 0000000..ae383ff Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=11.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=12.bin b/test/fixtures/binary_compare/deflate_windowBits=12.bin new file mode 100644 index 0000000..ea26586 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=12.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=13.bin b/test/fixtures/binary_compare/deflate_windowBits=13.bin new file mode 100644 index 0000000..5bdcb35 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=13.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=14.bin b/test/fixtures/binary_compare/deflate_windowBits=14.bin new file mode 100644 index 0000000..bb137f0 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=14.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=15.bin b/test/fixtures/binary_compare/deflate_windowBits=15.bin new file mode 100644 index 0000000..c3df954 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=15.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=8.bin b/test/fixtures/binary_compare/deflate_windowBits=8.bin new file mode 100644 index 0000000..8032592 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=8.bin differ diff --git a/test/fixtures/binary_compare/deflate_windowBits=9.bin b/test/fixtures/binary_compare/deflate_windowBits=9.bin new file mode 100644 index 0000000..8032592 Binary files /dev/null and b/test/fixtures/binary_compare/deflate_windowBits=9.bin differ diff --git a/test/fixtures/binary_compare/gzip.bin b/test/fixtures/binary_compare/gzip.bin new file mode 100644 index 0000000..3558d1f Binary files /dev/null and b/test/fixtures/binary_compare/gzip.bin differ diff --git a/test/helpers.js b/test/helpers.js index 562d135..6267787 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -46,44 +46,6 @@ function cmpBuf(a, b) { return true; } - -// Helper to test deflate/inflate with different options. -// Use zlib streams, because it's the only way to define options. -// -function testSingle(zlib_method, pako_method, data, options) { - var zlib_options = Object.assign({}, options); - - // hack for testing negative windowBits - if (zlib_options.windowBits < 0) { zlib_options.windowBits = -zlib_options.windowBits; } - - var zlib_result = zlib_method(b(data), zlib_options); - var pako_result = pako_method(data, options); - - // One more hack: gzip header contains OS code, that can vary. - // Override OS code if requested. For simplicity, we assume it on fixed - // position (= no additional gzip headers used) - if (options.ignore_os) zlib_result[9] = pako_result[9]; - - assert.deepEqual(new Uint8Array(pako_result), zlib_result); -} - - -function testSamples(zlib_method, pako_method, samples, options) { - - Object.keys(samples).forEach(function (name) { - var data = samples[name]; - - // with untyped arrays - setTyped(false); - testSingle(zlib_method, pako_method, data, options); - - // with typed arrays - setTyped(true); - testSingle(zlib_method, pako_method, data, options); - }); -} - - function testInflate(samples, inflateOptions, deflateOptions) { var name, data, deflated, inflated; @@ -109,4 +71,4 @@ function testInflate(samples, inflateOptions, deflateOptions) { } } -export { cmpBuf, testSamples, testInflate, loadSamples }; +export { cmpBuf, testInflate, loadSamples }; diff --git a/test/inflate.js b/test/inflate.js index 62352af..ad43825 100644 --- a/test/inflate.js +++ b/test/inflate.js @@ -4,11 +4,8 @@ import { assert, describe, it } from 'vitest'; import zlib from 'zlib'; import * as pako from '../lib/main'; -import * as helpers from './helpers'; -var testInflate = helpers.testInflate; - - -var samples = helpers.loadSamples(); +import { testInflate, loadSamples } from './helpers'; +var samples = loadSamples(); describe('Inflate defaults', function () { @@ -20,9 +17,12 @@ describe('Inflate defaults', function () { testInflate(samples, { raw: true }, { raw: true }); }); - it('inflate raw from compressed samples', function () { - var compressed_samples = helpers.loadSamples('samples_deflated_raw'); - helpers.testSamples(zlib.inflateRawSync, pako.inflateRaw, compressed_samples, {}); + it('inflate raw from compressed samples', () => { + Object.values(loadSamples('samples_deflated_raw')).forEach(function (sample) { + const pako_result = pako.inflateRaw(sample); + const zlib_result = zlib.inflateRawSync(sample); + assert.deepStrictEqual(pako_result, new Uint8Array(zlib_result)); + }); }); });