-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
55 lines (36 loc) · 1.28 KB
/
test.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
const fs = require('fs');
const path = require('path');
// const zlib = require('zlib');
const {
compress, decompress, deflate, deflateSync
} = require('../');
const test = async () => {
const json = require('../test/test.json');
for (const s of json.list) {
const cs = compress(s);
console.log(cs);
const ds = decompress(cs);
if (ds !== s) {
throw new Error('compress/decompress error');
}
}
// for browser
const jsonStr = JSON.stringify(json);
const dStr = compress(jsonStr);
const iStr = await deflate(jsonStr);
const iStrSync = deflateSync(jsonStr);
console.assert(iStrSync === iStr);
const testData = `window.testData = { raw: ${jsonStr}, decompressStr: "${dStr}", inflateStr: "${iStr}" };`;
fs.writeFileSync(path.resolve(__dirname, '../.temp/test.data.js'), testData);
// const tempStr = '1234567890';
// const buf = Buffer.from(tempStr);
// const dRaw = zlib.deflateRawSync(buf);
// console.log(dRaw);
// const d = zlib.deflateSync(buf);
// console.log(d);
// const dr = new Uint8Array(d.buffer, d.byteOffset + 2, d.length - 6);
// console.log(Buffer.from(dr));
// const gz = zlib.gzipSync(buf);
// console.log(Buffer.from(gz));
};
test();