0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-zlib-brotli-from-brotli.js
Livia Medeiros 966e3d3493
test: use tmpdir.resolve()
PR-URL: https://github.com/nodejs/node/pull/49128
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-08-15 13:45:44 +00:00

32 lines
985 B
JavaScript

'use strict';
// Test unzipping a file that was created with a non-node brotli lib,
// piped in as fast as possible.
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const decompress = new zlib.BrotliDecompress();
const fs = require('fs');
const fixture = fixtures.path('person.jpg.br');
const unzippedFixture = fixtures.path('person.jpg');
const outputFile = tmpdir.resolve('person.jpg');
const expect = fs.readFileSync(unzippedFixture);
const inp = fs.createReadStream(fixture);
const out = fs.createWriteStream(outputFile);
inp.pipe(decompress).pipe(out);
out.on('close', common.mustCall(() => {
const actual = fs.readFileSync(outputFile);
assert.strictEqual(actual.length, expect.length);
for (let i = 0, l = actual.length; i < l; i++) {
assert.strictEqual(actual[i], expect[i], `byte[${i}]`);
}
}));