-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgzip_specials.js
81 lines (61 loc) · 2.01 KB
/
gzip_specials.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
import { assert, describe, it } from 'vitest';
import fs from 'fs';
import path from 'path';
import { arraySet, Buf8 } from '../lib/utils/common';
import * as pako from '../lib/main';
import { cmpBuf as cmp } from './helpers';
function a2s(array) {
return String.fromCharCode.apply(null, array);
}
describe('Gzip special cases', function () {
it('Read custom headers', function () {
var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-headers.gz'));
var inflator = new pako.Inflate();
inflator.push(data, true);
assert.equal(inflator.header.name, 'test name');
assert.equal(inflator.header.comment, 'test comment');
assert.equal(a2s(inflator.header.extra), 'test extra');
});
it('Write custom headers', function () {
var data = ' ';
var deflator = new pako.Deflate({
gzip: true,
header: {
hcrc: true,
time: 1234567,
os: 15,
name: 'test name',
comment: 'test comment',
extra: [ 4, 5, 6 ]
}
});
deflator.push(data, true);
var inflator = new pako.Inflate({ to: 'string' });
inflator.push(deflator.result, true);
assert.equal(inflator.err, 0);
assert.equal(inflator.result, data);
var header = inflator.header;
assert.equal(header.time, 1234567);
assert.equal(header.os, 15);
assert.equal(header.name, 'test name');
assert.equal(header.comment, 'test comment');
assert(cmp(header.extra, [ 4, 5, 6 ]));
});
it('Read stream with SYNC marks', function () {
var inflator, strm, _in, len, pos = 0, i = 0;
var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-joined.gz'));
do {
len = data.length - pos;
_in = Buf8(len);
arraySet(_in, data, pos, len, 0);
inflator = new pako.Inflate();
strm = inflator.strm;
inflator.push(_in, true);
assert(!inflator.err, inflator.msg);
pos += strm.next_in;
i++;
} while (strm.avail_in);
assert(i === 2, 'invalid blobs count');
});
});