-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
Copy pathdeflate.js
41 lines (28 loc) · 1.06 KB
/
deflate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const pako = require('../index');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
describe('Deflate dictionary', () => {
it('handles multiple pushes', () => {
const dict = Buffer.from('abcd');
const deflate = new pako.Deflate({ dictionary: dict });
deflate.push(Buffer.from('hello'), false);
deflate.push(Buffer.from('hello'), false);
deflate.push(Buffer.from(' world'), true);
if (deflate.err) { throw new Error(deflate.err); }
const uncompressed = pako.inflate(Buffer.from(deflate.result), { dictionary: dict });
assert.deepStrictEqual(
new Uint8Array(Buffer.from('hellohello world')),
uncompressed
);
});
});
describe('Deflate issues', () => {
it('#78', () => {
const data = fs.readFileSync(path.join(__dirname, 'fixtures', 'issue_78.bin'));
const deflatedPakoData = pako.deflate(data, { memLevel: 1 });
const inflatedPakoData = pako.inflate(deflatedPakoData);
assert.strictEqual(data.length, inflatedPakoData.length);
});
});