Skip to content

Commit f6863e6

Browse files
comments
1 parent 5375216 commit f6863e6

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

etc/install-zstd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ download_zstd() {
1414
}
1515

1616
build_zstd() {
17-
export MACOSX_DEPLOYMENT_TARGET=10.12
17+
export MACOSX_DEPLOYMENT_TARGET=11
1818
cd deps/zstd/build/cmake
1919

2020
cmake .

lib/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
'use strict';
22
const zstd = require('bindings')('zstd');
33
const { promisify } = require('util');
4+
const { isArrayBufferView } = require('util/types');
45

56
const _compress = promisify(zstd.compress);
67
const _decompress = promisify(zstd.decompress);
78
// Error objects created via napi don't have JS stacks; wrap them so .stack is present
89
// https://github.com/nodejs/node/issues/25318#issuecomment-451068073
910

1011
exports.compress = async function compress(data, compressionLevel) {
11-
if (!Buffer.isBuffer(data)) {
12-
throw new TypeError(`parameter 'data' must be a Buffer.`);
12+
const isUint8Array = isArrayBufferView(data) && data instanceof Uint8Array;
13+
if (!isUint8Array) {
14+
throw new TypeError(`parameter 'data' must be a Uint8Array.`);
1315
}
1416

1517
if (compressionLevel != null && typeof compressionLevel !== 'number') {
@@ -23,8 +25,9 @@ exports.compress = async function compress(data, compressionLevel) {
2325
}
2426
};
2527
exports.decompress = async function decompress(data) {
26-
if (!Buffer.isBuffer(data)) {
27-
throw new TypeError(`parameter 'data' must be a Buffer.`);
28+
const isUint8Array = isArrayBufferView(data) && data instanceof Uint8Array;
29+
if (!isUint8Array) {
30+
throw new TypeError(`parameter 'data' must be a Uint8Array.`);
2831
}
2932
try {
3033
return await _decompress(data);

test/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { describe, test } = require('mocha');
1+
const { test } = require('mocha');
22
const { compress, decompress } = require('../lib/index');
33

44
const zstdLegacy = require('@mongodb-js/zstd');
@@ -14,7 +14,7 @@ describe('decompress', function () {
1414
test('decompress() throws a TypeError', async function () {
1515
expect(await decompress().catch(e => e))
1616
.to.be.instanceOf(TypeError)
17-
.to.match(/must be a buffer/i);
17+
.to.match(/must be a uint8array/i);
1818
});
1919

2020
test('decompress() returns a Nodejs buffer', async function () {
@@ -27,7 +27,7 @@ describe('compress', function () {
2727
test('compress() throws a TypeError', async function () {
2828
expect(await compress().catch(e => e))
2929
.to.be.instanceOf(TypeError)
30-
.to.match(/must be a buffer/i);
30+
.to.match(/must be a uint8array/i);
3131
});
3232

3333
test('compress() returns a Nodejs buffer', async function () {

0 commit comments

Comments
 (0)