Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-6540): Add c++ zstd compression API #30

Merged
merged 21 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Anna"s comment
  • Loading branch information
baileympearson committed Nov 19, 2024
commit aba799c4473365622561fe7c3048b882d0b7c22b
8 changes: 3 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';
const zstd = require('bindings')('zstd');
addaleax marked this conversation as resolved.
Show resolved Hide resolved
const { promisify } = require('util');
const { isArrayBufferView } = require('util/types');
const { isUint8Array } = require('util/types');

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

exports.compress = async function compress(data, compressionLevel) {
const isUint8Array = isArrayBufferView(data) && data instanceof Uint8Array;
if (!isUint8Array) {
if (!isUint8Array(data)) {
throw new TypeError(`parameter 'data' must be a Uint8Array.`);
}

@@ -25,8 +24,7 @@ exports.compress = async function compress(data, compressionLevel) {
}
};
exports.decompress = async function decompress(data) {
const isUint8Array = isArrayBufferView(data) && data instanceof Uint8Array;
if (!isUint8Array) {
if (!isUint8Array(data)) {
throw new TypeError(`parameter 'data' must be a Uint8Array.`);
}
try {