|
| 1 | +'use strict' |
| 2 | +// Test compressing and uncompressing a string with zstd |
| 3 | + |
| 4 | +import t from 'tap' |
| 5 | +import {ZstdCompress, ZstdDecompress} from '../dist/esm/index.js' |
| 6 | + |
| 7 | +const inputString = |
| 8 | + 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli' + |
| 9 | + 't. Morbi faucibus, purus at gravida dictum, libero arcu ' + |
| 10 | + 'convallis lacus, in commodo libero metus eu nisi. Nullam' + |
| 11 | + ' commodo, neque nec porta placerat, nisi est fermentum a' + |
| 12 | + 'ugue, vitae gravida tellus sapien sit amet tellus. Aenea' + |
| 13 | + 'n non diam orci. Proin quis elit turpis. Suspendisse non' + |
| 14 | + ' diam ipsum. Suspendisse nec ullamcorper odio. Vestibulu' + |
| 15 | + 'm arcu mi, sodales non suscipit id, ultrices ut massa. S' + |
| 16 | + 'ed ac sem sit amet arcu malesuada fermentum. Nunc sed. ' |
| 17 | +const compressedString = |
| 18 | + 'KLUv/WT5AF0JAGbXPCCgJUkH/8+rqgA3KaVsW+6LfK3JL' + |
| 19 | + 'cnP+I/Gy1/3Qv9XDTQAMwA0AK+Ch9LCub6tnT62C7Quwr' + |
| 20 | + 'HQHDhhNPcCQltMWOrafGy3KO2D79QZ95omy09vwp/TFEA' + |
| 21 | + 'kEIlHOO99cOlZmfRizXQ79GvDoY9TxrTgBBfR+77Nd7Lk' + |
| 22 | + 'OWlHaGW+aEwd2rSeegWaj9NsWAJJ0253u1jQpe3ByWLS5' + |
| 23 | + 'i+24QhTAZygaf4UlqNER3XoAk7QYar9tjHHV4yHj+tC10' + |
| 24 | + '8zuqMBJ+X2hlpwUqX6vE3r3N7q5QYntVvn3N8zVDb9UfC' + |
| 25 | + 'MCW1790yV3A88pgvkvQAniSWvFxMAELvECFu0tC1R9Ijs' + |
| 26 | + 'ri5bt2kE/2mLoi2wCpkElnidDMS//DemxlNdHClyl6KeN' + |
| 27 | + 'TCugmAGfEYAXA==' |
| 28 | + |
| 29 | +t.test('compress then decompress', async t => |
| 30 | + new ZstdCompress() |
| 31 | + .end(inputString) |
| 32 | + .concat() |
| 33 | + .then(async buffer => { |
| 34 | + t.ok( |
| 35 | + inputString.length > buffer.length, |
| 36 | + 'buffer is shorter than input', |
| 37 | + ) |
| 38 | + |
| 39 | + return new ZstdDecompress() |
| 40 | + .end(buffer) |
| 41 | + .concat() |
| 42 | + .then(buffer => t.equal(buffer.toString(), inputString)) |
| 43 | + }), |
| 44 | +) |
| 45 | + |
| 46 | +t.test('decompress then check', t => |
| 47 | + new ZstdDecompress({ encoding: 'utf8' }) |
| 48 | + .end(compressedString, 'base64') |
| 49 | + .concat() |
| 50 | + .then(result => t.equal(result, inputString)), |
| 51 | +) |
0 commit comments