Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"url": "git://github.com/Topface/node-lzf.git"
},
"dependencies": {
"nan": "1.3.0"
"nan": "^2.0.9"
},
"directories": {
"lib": "./lib"
},
"main": "./index",
"scripts": {
"test": "node test/test.js"
}
},
"license": "BSD-2-Clause"
}
43 changes: 19 additions & 24 deletions src/lzf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,70 @@ using namespace node;


// Handle<Value> ThrowNodeError(const char* what = NULL) {
// return NanThrowError(Exception::Error(NanNew<String>(what)));
// return Nan::ThrowError(Exception::Error(Nan::New<String>(what)));
// }
NAN_METHOD(compress) {
if (args.Length() < 1 || !Buffer::HasInstance(args[0])) {
return NanThrowError("First argument must be a Buffer");
if (info.Length() < 1 || !Buffer::HasInstance(info[0])) {
return Nan::ThrowError("First argument must be a Buffer");
}
NanScope();

Local<Object> bufferIn = args[0]->ToObject();
Local<Object> bufferIn = info[0]->ToObject();
size_t bytesIn = Buffer::Length(bufferIn);
char * dataPointer = Buffer::Data(bufferIn);
size_t bytesCompressed = bytesIn + 100;
char * bufferOut = (char*) malloc(bytesCompressed);

if (!bufferOut) {
return NanThrowError("LZF malloc failed!");
return Nan::ThrowError("LZF malloc failed!");
}

unsigned result = lzf_compress(dataPointer, bytesIn, bufferOut, bytesCompressed);

if (!result) {
free(bufferOut);
return NanThrowError("Compression failed, probably too small buffer");
return Nan::ThrowError("Compression failed, probably too small buffer");
}

Local<Object> BufferOut = NanNewBufferHandle(bufferOut, result);
free(bufferOut);
Nan::MaybeLocal<Object> BufferOut = Nan::NewBuffer(bufferOut, result);

NanReturnValue(BufferOut);
info.GetReturnValue().Set(BufferOut.ToLocalChecked());
}


NAN_METHOD(decompress) {
if (args.Length() < 1 || !Buffer::HasInstance(args[0])) {
return NanThrowError("First argument must be a Buffer");
if (info.Length() < 1 || !Buffer::HasInstance(info[0])) {
return Nan::ThrowError("First argument must be a Buffer");
}

Local<Object> bufferIn = args[0]->ToObject();
Local<Object> bufferIn = info[0]->ToObject();

size_t bytesUncompressed = 999 * 1024 * 1024; // it's about max size that V8 supports

if (args.Length() > 1 && args[1]->IsNumber()) { // accept dest buffer size
bytesUncompressed = args[1]->Uint32Value();
if (info.Length() > 1 && info[1]->IsNumber()) { // accept dest buffer size
bytesUncompressed = info[1]->Uint32Value();
}


char * bufferOut = (char*) malloc(bytesUncompressed);
if (!bufferOut) {
return NanThrowError("LZF malloc failed!");
return Nan::ThrowError("LZF malloc failed!");
}

unsigned result = lzf_decompress(Buffer::Data(bufferIn), Buffer::Length(bufferIn), bufferOut, bytesUncompressed);

if (!result) {
return NanThrowError("Unrompression failed, probably too small buffer");
return Nan::ThrowError("Unrompression failed, probably too small buffer");
}

Local<Object> BufferOut = NanNewBufferHandle(bufferOut, result);
Nan::MaybeLocal<Object> BufferOut = Nan::NewBuffer(bufferOut, result);

free(bufferOut);

NanScope();
NanReturnValue(BufferOut);
info.GetReturnValue().Set(BufferOut.ToLocalChecked());
}

extern "C" void
init (Handle<Object> target) {
NODE_SET_METHOD(target, "compress", compress);
NODE_SET_METHOD(target, "decompress", decompress);
Nan::SetMethod(target, "compress", compress);
Nan::SetMethod(target, "decompress", decompress);
}

NODE_MODULE(lzf, init)
4 changes: 3 additions & 1 deletion src/lzf/lzfP.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ using namespace std;
# if defined (WIN32)
# define LZF_USE_OFFSETS defined(_M_X64)
# else
# if __cplusplus > 199711L
# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bobrik: I didn't even look at that PR because of the title >_<. Isn't my commit safer as it leaves all existing logic in and fixes the problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still changes liblzf and I still believe that this change should go upstream (liblzf itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely should, I'm just trying to help the community transition to
Node 4.0. I will try to do this later today.

On Mon, Sep 21, 2015 at 9:15 AM, Ian Babrou notifications@github.com
wrote:

In src/lzf/lzfP.h
#9 (comment):

@@ -144,7 +144,9 @@ using namespace std;

if defined (WIN32)

define LZF_USE_OFFSETS defined(_M_X64)

else

-# if __cplusplus > 199711L
+# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8

It still changes liblzf and I still believe that this change should go
upstream (liblzf itself)


Reply to this email directly or view it on GitHub
https://github.com/Topface/node-lzf/pull/9/files#r39968314.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmealo did you write to the author of Liblzf?

# include <tr1/cstdint>
# elif __cplusplus > 199711L
# include <cstdint>
# else
# include <stdint.h>
Expand Down