Skip to content

Commit 5375216

Browse files
changes
1 parent 1abda0f commit 5375216

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"overrides": [
6767
{
68-
"files": ["lib/*js"],
68+
"files": ["lib/*.js"],
6969
"parserOptions": {
7070
"ecmaVersion": 2019,
7171
"sourceType": "commonjs"

addon/compression.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
#include "compression.h"
42

53
std::vector<uint8_t> mongodb_zstd::compress(const std::vector<uint8_t>& data,

addon/compression_worker.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ namespace mongodb_zstd {
1212
* @brief An asynchronous Napi::Worker that can be with any function that produces
1313
* CompressionResults.
1414
* */
15-
class CompressionWorker final : public Napi::AsyncWorker {
15+
class CompressionWorker final : public AsyncWorker {
1616
public:
17-
CompressionWorker(const Napi::Function& callback, std::function<std::vector<uint8_t>()> worker)
18-
: Napi::AsyncWorker{callback, "compression worker"}, m_worker(worker), m_result{} {}
17+
CompressionWorker(const Function& callback, std::function<std::vector<uint8_t>()> worker)
18+
: AsyncWorker{callback, "compression worker"}, m_worker(worker), m_result{} {}
1919

2020
protected:
21-
void Execute() {
21+
void Execute() final {
2222
m_result = m_worker();
2323
}
2424

25-
void OnOK() {
25+
void OnOK() final {
2626
if (!m_result.has_value()) {
27-
Callback().Call({Napi::Error::New(Env(),
28-
"zstd runtime error - async worker finished without "
29-
"a compression or decompression result.")
27+
Callback().Call({Error::New(Env(),
28+
"zstd runtime - async worker finished without "
29+
"a compression or decompression result.")
3030
.Value()});
3131
return;
3232
}
3333

34-
std::vector<uint8_t> data = *m_result;
34+
const std::vector<uint8_t>& data = m_result.value();
3535
Buffer result = Buffer<uint8_t>::Copy(Env(), data.data(), data.size());
3636

3737
Callback().Call({Env().Undefined(), result});

addon/zstd.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using namespace Napi;
1111

1212
namespace mongodb_zstd {
13-
void Compress(const Napi::CallbackInfo& info) {
13+
void Compress(const CallbackInfo& info) {
1414
// Argument handling happens in JS
1515
if (info.Length() != 3) {
1616
const char* error_message = "Expected three arguments.";
@@ -21,7 +21,7 @@ void Compress(const Napi::CallbackInfo& info) {
2121
std::vector<uint8_t> data(to_compress.Data(), to_compress.Data() + to_compress.ElementLength());
2222

2323
size_t compression_level = static_cast<size_t>(info[1].ToNumber().Int32Value());
24-
const Napi::Function& callback = info[2].As<Function>();
24+
Function callback = info[2].As<Function>();
2525

2626
CompressionWorker* worker =
2727
new CompressionWorker(callback, [data = std::move(data), compression_level] {
@@ -38,20 +38,20 @@ void Decompress(const CallbackInfo& info) {
3838
throw TypeError::New(info.Env(), error_message);
3939
}
4040

41-
Napi::Uint8Array compressed_data = info[0].As<Uint8Array>();
41+
Uint8Array compressed_data = info[0].As<Uint8Array>();
4242
std::vector<uint8_t> data(compressed_data.Data(),
4343
compressed_data.Data() + compressed_data.ElementLength());
44-
const Napi::Function& callback = info[1].As<Function>();
44+
Function callback = info[1].As<Function>();
4545

4646
CompressionWorker* worker = new CompressionWorker(
4747
callback, [data = std::move(data)] { return mongodb_zstd::decompress(data); });
4848

4949
worker->Queue();
5050
}
5151

52-
Napi::Object Init(Napi::Env env, Napi::Object exports) {
53-
exports.Set(Napi::String::New(env, "compress"), Napi::Function::New(env, Compress));
54-
exports.Set(Napi::String::New(env, "decompress"), Napi::Function::New(env, Decompress));
52+
Object Init(Env env, Object exports) {
53+
exports.Set(String::New(env, "compress"), Function::New(env, Compress));
54+
exports.Set(String::New(env, "decompress"), Function::New(env, Decompress));
5555
return exports;
5656
}
5757

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
'msvs_settings': {
3030
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
3131
},
32-
'link_settings': {
32+
'link_settings': {
3333
'libraries': [
3434
'<(module_root_dir)/deps/zstd/build/cmake/lib/libzstd.a',
3535
]

0 commit comments

Comments
 (0)