summaryrefslogtreecommitdiff
path: root/test/parallel/test-zlib-maxOutputLength.js
blob: 9af0b3736f881599cdb72d03290980381db759b7 (plain)
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
'use strict';
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');

const encoded = Buffer.from('G38A+CXCIrFAIAM=', 'base64');

// Async
zlib.brotliDecompress(encoded, { maxOutputLength: 64 }, common.expectsError({
  code: 'ERR_BUFFER_TOO_LARGE',
  message: 'Cannot create a Buffer larger than 64 bytes'
}));

// Sync
assert.throws(function() {
  zlib.brotliDecompressSync(encoded, { maxOutputLength: 64 });
}, RangeError);

// Async
zlib.brotliDecompress(encoded, { maxOutputLength: 256 }, function(err) {
  assert.strictEqual(err, null);
});

// Sync
zlib.brotliDecompressSync(encoded, { maxOutputLength: 256 });