Geen omschrijving

test-zlib-params.js 955B

123456789101112131415161718192021222324252627282930313233
  1. var common = require('../common.js');
  2. var assert = require('assert');
  3. var zlib = require('zlib');
  4. var path = require('path');
  5. var fs = require('fs');
  6. var file = fs.readFileSync(path.resolve(common.fixturesDir, 'person.jpg')),
  7. chunkSize = 24 * 1024,
  8. opts = { level: 9, strategy: zlib.Z_DEFAULT_STRATEGY },
  9. deflater = zlib.createDeflate(opts);
  10. var chunk1 = file.slice(0, chunkSize),
  11. chunk2 = file.slice(chunkSize),
  12. blkhdr = new Buffer([0x00, 0x48, 0x82, 0xb7, 0x7d]),
  13. expected = Buffer.concat([blkhdr, chunk2]),
  14. actual;
  15. deflater.write(chunk1, function() {
  16. deflater.params(0, zlib.Z_DEFAULT_STRATEGY, function() {
  17. while (deflater.read());
  18. deflater.end(chunk2, function() {
  19. var bufs = [], buf;
  20. while (buf = deflater.read())
  21. bufs.push(buf);
  22. actual = Buffer.concat(bufs);
  23. });
  24. });
  25. while (deflater.read());
  26. });
  27. process.once('exit', function() {
  28. assert.deepEqual(actual, expected);
  29. });