Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
Use NAPI_MODULE_INIT
Browse files Browse the repository at this point in the history
This allows iltorb to be loaded multiple times during the lifetime of the Node.js process.

Fix #78
  • Loading branch information
nstepien committed Oct 24, 2018
1 parent 111a9df commit cd07dff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/iltorb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#include "dec/stream_decode.h"
#include "enc/stream_encode.h"

napi_value Init(napi_env env, napi_value exports) {
NAPI_MODULE_INIT() {
StreamDecode::Init(env, exports);
StreamEncode::Init(env, exports);
return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
15 changes: 15 additions & 0 deletions test/iltorb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from 'ava';

test('compress an empty buffer', async function(t) {
const brotli1 = require('../');
const buf1 = await brotli1.compress(Buffer.alloc(0));
t.truthy(Buffer.isBuffer(buf1));

delete require.cache[require.resolve('..')];
delete require.cache[require.resolve('../build/bindings/iltorb.node')];

const brotli2 = require('../');
const buf2 = await brotli2.compress(Buffer.alloc(0));
t.truthy(Buffer.isBuffer(buf2));
t.truthy(Buffer.compare(buf1, buf2) === 0);
});

0 comments on commit cd07dff

Please sign in to comment.