Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions addon/zstd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "zstd.h"

#define NAPI_VERSION 9

#include <napi.h>

#include <vector>
Expand Down Expand Up @@ -49,9 +51,17 @@ void Decompress(const CallbackInfo& info) {
worker->Queue();
}

Value GetDefinedNapiVersion(const CallbackInfo& info) {
return Napi::String::New(info.Env(), std::to_string(NAPI_VERSION));
}

Object Init(Env env, Object exports) {
exports.Set(String::New(env, "compress"), Function::New(env, Compress));
exports.Set(String::New(env, "decompress"), Function::New(env, Decompress));

exports.Set(String::New(env, "getDefinedNapiVersion"),
Function::New(env, GetDefinedNapiVersion));

return exports;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exports.compress = async function compress(data, compressionLevel) {
throw new Error(`zstd: ${e.message}`);
}
};

exports.decompress = async function decompress(data) {
if (!isUint8Array(data)) {
throw new TypeError(`parameter 'data' must be a Uint8Array.`);
Expand All @@ -49,3 +50,6 @@ exports.decompress = async function decompress(data) {
throw new Error(`zstd: ${e.message}`);
}
};

/** used for testing */
exports.getDefinedNapiVersion = zstd.getDefinedNapiVersion;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
},
"binary": {
"napi_versions": [
4
9
]
},
"mongodb:zstd_version": "1.5.6"
}
}
4 changes: 1 addition & 3 deletions test/bundling/webpack/install_zstd.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { execSync } = require('node:child_process');
const { readFileSync } = require('node:fs');
const { resolve } = require('node:path');
Expand All @@ -19,6 +17,6 @@ console.log(`zstd Version: ${zstdVersion}`);

xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: zstdRoot });

xtrace(`npm install --no-save mongodb-js-zstd-${zstdVersion}.tgz`);
xtrace(`npm install --ignore-scripts --no-save mongodb-js-zstd-${zstdVersion}.tgz`);

console.log('zstd installed!');
8 changes: 7 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { test } = require('mocha');
const { compress, decompress } = require('../lib/index');
const { compress, decompress, getDefinedNapiVersion } = require('../lib/index');

const { expect } = require('chai');

Expand Down Expand Up @@ -55,6 +55,12 @@ describe('compress', function () {
});
});

describe('misc', function () {
test('getDefinedNapiVersion() returns 9', function () {
expect(getDefinedNapiVersion()).to.equal('9');
});
});

/**
* @param {import('../index').decompress} decompress
* @param {import('../index').compress} compress
Expand Down