Skip to content

Commit

Permalink
other comments
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Nov 15, 2024
1 parent 251003c commit 04030a0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 52 deletions.
6 changes: 3 additions & 3 deletions addon/compression_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ using namespace Napi;
* @brief An asynchronous Napi::Worker that can be with any function that produces
* CompressionResults.
* */
class CompressionWorker : public Napi::AsyncWorker {
class CompressionWorker final : public Napi::AsyncWorker {
public:
CompressionWorker(const Napi::Function& callback, std::function<std::vector<uint8_t>()> worker)
: Napi::AsyncWorker{callback, "compression worker"}, m_worker(worker), m_result{} {}

protected:
void Execute() {
void Execute() final {
m_result = m_worker();
}

void OnOK() {
void OnOK() final {
if (!m_result.has_value()) {
Callback().Call({Napi::Error::New(Env(),
"zstd runtime error - async worker finished without "
Expand Down
40 changes: 0 additions & 40 deletions addon/napi_utils.h

This file was deleted.

15 changes: 8 additions & 7 deletions addon/zstd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ using namespace Napi;
void Compress(const Napi::CallbackInfo& info) {
// Argument handling happens in JS
if (info.Length() != 3) {
std::string error_message = "Expected two arguments.";
std::string error_message = "Expected three arguments.";
throw TypeError::New(info.Env(), error_message);
}

Uint8Array to_compress = Uint8ArrayFromValue(info[0], "buffer");
std::vector<uint8_t> data = getBytesFromUint8Array(to_compress);
Uint8Array to_compress = info[0].As<Uint8Array>();
std::vector<uint8_t> data(to_compress.Data(), to_compress.Data() + to_compress.ElementLength());

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

CompressionWorker* worker =
Expand All @@ -35,12 +35,13 @@ void Compress(const Napi::CallbackInfo& info) {
void Decompress(const CallbackInfo& info) {
// Argument handling happens in JS
if (info.Length() != 2) {
std::string error_message = "Expected one argument.";
std::string error_message = "Expected two argument.";
throw TypeError::New(info.Env(), error_message);
}

Napi::Uint8Array compressed_data = Uint8ArrayFromValue(info[0], "buffer");
std::vector<uint8_t> data = getBytesFromUint8Array(compressed_data);
Napi::Uint8Array compressed_data = info[0].As<Uint8Array>();
std::vector<uint8_t> data(compressed_data.Data(),
compressed_data.Data() + compressed_data.ElementLength());
const Napi::Function& callback = info[1].As<Function>();

CompressionWorker* worker = new CompressionWorker(
Expand Down
3 changes: 1 addition & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
'addon/zstd.cpp',
'addon/compression_worker.h',
'addon/compression.h',
'addon/compression.cpp',
'addon/napi_utils.h',
'addon/compression.cpp'
],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

Check failure on line 1 in lib/index.js

View workflow job for this annotation

GitHub Actions / typescript

'use strict' is unnecessary inside of modules

const zstd = require('bindings')('zstd');
const { promisify } = require('util');

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"node": ">= 16.20.1"
},
"scripts": {
"prepare": "npm run compile",
"compile": "node-gyp rebuild",

"test": "mocha test/index.test.js",
Expand Down

0 comments on commit 04030a0

Please sign in to comment.