-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69dac28
commit b1b8fd0
Showing
11 changed files
with
238 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,37 @@ | |
'type': 'loadable_module', | ||
'defines': ['ZSTD_STATIC_LINKING_ONLY'], | ||
'include_dirs': [ | ||
"<(module_root_dir)/deps/zstd/lib", | ||
"<!(node -p \"require('node-addon-api').include_dir\")" | ||
], | ||
'variables': { | ||
'ARCH': '<(host_arch)', | ||
'libmongocrypt_link_type%': 'static', | ||
'mongocrypt_avoid_openssl_crypto%': 'false', | ||
'built_with_electron%': 0 | ||
}, | ||
'sources': [ | ||
'src/addon.cpp' | ||
'src/addon.cpp', | ||
'src/napi_utils.h', | ||
'src/compressor.h', | ||
'src/decompressor.h', | ||
'src/compression_worker.h' | ||
], | ||
'xcode_settings': { | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', | ||
'CLANG_CXX_LIBRARY': 'libc++', | ||
'MACOSX_DEPLOYMENT_TARGET': '10.12', | ||
# mongodb-client-encryption targets 10.12, but our [email protected] targeted 10.13. | ||
'MACOSX_DEPLOYMENT_TARGET': '10.13', | ||
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden | ||
}, | ||
'cflags!': [ '-fno-exceptions' ], | ||
'cflags_cc!': [ '-fno-exceptions' ], | ||
'cflags_cc': [ '-std=c++17' ], | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { 'ExceptionHandling': 1 }, | ||
} | ||
}, | ||
'link_settings': { | ||
'libraries': [ | ||
'<(module_root_dir)/deps/zstd/lib/libzstd.a', | ||
] | ||
}, | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export declare function compress(data: Buffer, level?: number | undefined | null): Promise<Buffer> | ||
export declare function decompress(data: Buffer): Promise<Buffer> | ||
export declare function compress(data: Buffer, level?: number | undefined | null): Promise<Buffer>; | ||
export declare function decompress(data: Buffer): Promise<Buffer>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#include <vector> | ||
#include <napi.h> | ||
|
||
#include "zstd.h" | ||
|
||
using namespace Napi; | ||
|
||
struct Compressor { | ||
std::vector<uint8_t> data; | ||
size_t compression_level; | ||
|
||
Compressor(std::vector<uint8_t> data, size_t compression_level) | ||
: data(data), compression_level(compression_level) {} | ||
|
||
CompressionResult operator()() { | ||
size_t output_buffer_size = ZSTD_compressBound(data.size()); | ||
std::vector<uint8_t> output(output_buffer_size); | ||
|
||
size_t result_code = ZSTD_compress( | ||
output.data(), output.size(), data.data(), data.size(), compression_level); | ||
|
||
if (ZSTD_isError(result_code)) { | ||
std::string error(ZSTD_getErrorName(result_code)); | ||
return CompressionResult::Error(error); | ||
} | ||
|
||
output.resize(result_code); | ||
|
||
return CompressionResult::Ok(output); | ||
} | ||
|
||
static Compressor fromUint8Array(const Uint8Array& to_compress, size_t compression_level) { | ||
const uint8_t* input_data = to_compress.Data(); | ||
size_t total = to_compress.ElementLength(); | ||
|
||
std::vector<uint8_t> data(to_compress.ElementLength()); | ||
|
||
std::copy(input_data, input_data + total, data.data()); | ||
|
||
return Compressor(std::move(data), compression_level); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <napi.h> | ||
|
||
#include <vector> | ||
|
||
|
||
|
||
#include "zstd.h" | ||
|
||
using namespace Napi; | ||
|
||
struct Decompressor { | ||
std::vector<uint8_t> data; | ||
size_t buffer_size; | ||
|
||
Decompressor(std::vector<uint8_t> data, size_t buffer_size) | ||
: data(data), buffer_size(buffer_size) {} | ||
|
||
CompressionResult operator()() { | ||
std::vector<uint8_t> decompressed(buffer_size); | ||
|
||
size_t _result = | ||
ZSTD_decompress(decompressed.data(), decompressed.size(), data.data(), data.size()); | ||
|
||
if (ZSTD_isError(_result)) { | ||
std::string error(ZSTD_getErrorName(_result)); | ||
return CompressionResult::Error(error); | ||
} | ||
|
||
decompressed.resize(_result); | ||
|
||
return CompressionResult::Ok(decompressed); | ||
} | ||
|
||
static Decompressor fromUint8Array(const Uint8Array& compressed_data) { | ||
const uint8_t* input_data = compressed_data.Data(); | ||
size_t total = compressed_data.ElementLength(); | ||
|
||
std::vector<uint8_t> data(total); | ||
std::copy(input_data, input_data + total, data.data()); | ||
|
||
return Decompressor(data, total * 1000); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.