Skip to content

Commit

Permalink
test: remove need to make fs call for zlib test
Browse files Browse the repository at this point in the history
PR-URL: #54814
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
anonrig authored and aduh95 committed Sep 13, 2024
1 parent fbd08e3 commit b998bb0
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions test/parallel/test-zlib-flush.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
'use strict';

require('../common');
const assert = require('assert');
const zlib = require('zlib');
const fixtures = require('../common/fixtures');

const file = fixtures.readSync('person.jpg');
const chunkSize = 16;
const opts = { level: 0 };
const deflater = zlib.createDeflate(opts);
const assert = require('node:assert');
const zlib = require('node:zlib');
const { test } = require('node:test');

test('zlib flush', async () => {
const { promise, resolve } = Promise.withResolvers();

const chunk = file.slice(0, chunkSize);
const expectedNone = Buffer.from([0x78, 0x01]);
const blkhdr = Buffer.from([0x00, 0x10, 0x00, 0xef, 0xff]);
const adler32 = Buffer.from([0x00, 0x00, 0x00, 0xff, 0xff]);
const expectedFull = Buffer.concat([blkhdr, chunk, adler32]);
let actualNone;
let actualFull;
const opts = { level: 0 };
const deflater = zlib.createDeflate(opts);
const chunk = Buffer.from('/9j/4AAQSkZJRgABAQEASA==', 'base64');
const expectedNone = Buffer.from([0x78, 0x01]);
const blkhdr = Buffer.from([0x00, 0x10, 0x00, 0xef, 0xff]);
const adler32 = Buffer.from([0x00, 0x00, 0x00, 0xff, 0xff]);
const expectedFull = Buffer.concat([blkhdr, chunk, adler32]);
let actualNone;
let actualFull;

deflater.write(chunk, function() {
deflater.flush(zlib.constants.Z_NO_FLUSH, function() {
actualNone = deflater.read();
deflater.flush(function() {
const bufs = [];
let buf;
while ((buf = deflater.read()) !== null)
bufs.push(buf);
actualFull = Buffer.concat(bufs);
deflater.write(chunk, function() {
deflater.flush(zlib.constants.Z_NO_FLUSH, function() {
actualNone = deflater.read();
deflater.flush(function() {
const bufs = [];
let buf;
while ((buf = deflater.read()) !== null)
bufs.push(buf);
actualFull = Buffer.concat(bufs);
resolve();
});
});
});
});

process.once('exit', function() {
await promise;
assert.deepStrictEqual(actualNone, expectedNone);
assert.deepStrictEqual(actualFull, expectedFull);
});

0 comments on commit b998bb0

Please sign in to comment.