Skip to content

Commit cc5db66

Browse files
committed
Exporting value for proper blocks handling, cleanup and npm
1 parent 12823c8 commit cc5db66

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Synchronous Buffer compression library for Node.js",
44
"homepage" : "http://egorfine.github.com/node-compress-buffer",
55
"bugs" : { "url" : "http://github.com/egorFiNE/node-compress-buffer/issues" },
6-
"version": "1.2.7",
6+
"version": "1.2.8",
77
"author": "Egor Egorov",
88
"repository": {
99
"type": "git",

src/compress-buffer.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static Persistent<String> SYM_BOUNDARY;
2828
static Persistent<String> SYM_LEFT;
2929
static Persistent<String> SYM_RIGHT;
3030
static Persistent<String> SYM_LAST_BLOCK;
31+
static Persistent<String> SYM_LAST_VALUE;
3132
static Persistent<String> SYM_TYPE;
3233
static Persistent<String> SYM_OFFSETS;
3334
static Persistent<String> SYM_LENGTH;
@@ -36,14 +37,13 @@ static Persistent<String> SYM_CRC;
3637
static Persistent<String> SYM_META;
3738
static Persistent<String> SYM_BUFFERS;
3839
static Persistent<String> SYM_HEADER;
39-
static Persistent<String> SYM_ODD;
4040
unsigned char *tmpBody;
4141

4242
static Handle<Value> ThrowNodeError (const char* what = NULL) {
4343
return ThrowException(Exception::Error(String::New(what)));
4444
}
4545

46-
static int meta_uncompress (char **dataIn, size_t bytesIn, char **dataBoundary, size_t *bytesBoundary, int *lastBlockPosition) {
46+
static int meta_uncompress (char **dataIn, size_t bytesIn, char **dataBoundary, size_t *bytesBoundary, int *lastBlockPosition, int *lastBlockValue) {
4747
int last;
4848
int pos;
4949

@@ -66,8 +66,8 @@ static int meta_uncompress (char **dataIn, size_t bytesIn, char **dataBoundary,
6666
//is there only one block in the stream?
6767
last = strmUncompress.next_in[0] & 1;
6868
if (last) {
69-
*(*dataIn + (bytesIn - strmUncompress.avail_in)) &= ~1;
7069
*lastBlockPosition = bytesIn - strmUncompress.avail_in;
70+
*lastBlockValue = 1;
7171
}
7272

7373
for (;;) {
@@ -100,13 +100,13 @@ static int meta_uncompress (char **dataIn, size_t bytesIn, char **dataBoundary,
100100
last = strmUncompress.next_in[-1] & pos;
101101
if (last) {
102102
*lastBlockPosition = bytesIn - strmUncompress.avail_in - 1;
103-
*(*dataIn + *lastBlockPosition) &= ~pos;
103+
*lastBlockValue = pos;
104104
}
105105
} else {
106106
last = strmUncompress.next_in[0] & 1;
107107
if (last) {
108108
*lastBlockPosition = bytesIn - strmUncompress.avail_in;
109-
*(*dataIn + *lastBlockPosition) &= ~1;
109+
*lastBlockValue = 1;
110110
}
111111
}
112112
}
@@ -228,6 +228,7 @@ static Handle<Value> onet_compress (const Arguments &args) {
228228
size_t bytesOut = 0;
229229
size_t bytesBoundary = 0;
230230
int lastBlockPosition = 0;
231+
int lastBlockValue = 0;
231232

232233
int status = compress(dataIn, bytesIn, compressionLevel, &dataOut, &bytesOut);
233234

@@ -242,7 +243,7 @@ static Handle<Value> onet_compress (const Arguments &args) {
242243
return Undefined();
243244
}
244245

245-
status = meta_uncompress(&dataOut, bytesOut, &dataBoundary, &bytesBoundary, &lastBlockPosition);
246+
status = meta_uncompress(&dataOut, bytesOut, &dataBoundary, &bytesBoundary, &lastBlockPosition, &lastBlockValue);
246247

247248
if (status != 0) {
248249
char msg[30];
@@ -271,6 +272,7 @@ static Handle<Value> onet_compress (const Arguments &args) {
271272
Local<Object> meta = Object::New();
272273
meta->Set(SYM_OFFSETS, dataOffsets);
273274
meta->Set(SYM_LENGTH, Integer::New(bytesIn));
275+
meta->Set(SYM_LAST_VALUE, Integer::New(lastBlockValue));
274276
meta->Set(SYM_RAW_LENGTH, Integer::New(bytesOut - HEADER_SIZE - FOOTER_SIZE));
275277
meta->Set(SYM_CRC, crc->handle_);
276278

@@ -481,6 +483,7 @@ extern "C" void init (Handle<Object> target) {
481483
SYM_LEFT = NODE_PSYMBOL("left");
482484
SYM_RIGHT = NODE_PSYMBOL("right");
483485
SYM_LAST_BLOCK = NODE_PSYMBOL("lastBlock");
486+
SYM_LAST_VALUE = NODE_PSYMBOL("lastValue");
484487
SYM_TYPE = NODE_PSYMBOL("type");
485488
SYM_OFFSETS = NODE_PSYMBOL("offsets");
486489
SYM_LENGTH = NODE_PSYMBOL("length");
@@ -489,18 +492,13 @@ extern "C" void init (Handle<Object> target) {
489492
SYM_META = NODE_PSYMBOL("meta");
490493
SYM_BUFFERS = NODE_PSYMBOL("buffers");
491494
SYM_HEADER = NODE_PSYMBOL("header");
492-
SYM_ODD = NODE_PSYMBOL("odd");
493495
tmpBody = (unsigned char *) malloc(CHUNK);
494496

495497
char header[] = {0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
496498
Buffer *headerBuffer = Buffer::New(header, 10);
497499

498-
char odd[] = {0x00, 0x00, 0xff, 0xff};
499-
Buffer *oddBuffer = Buffer::New(odd, 4);
500-
501500
Handle<Object> buffers = Object::New();
502501
buffers->Set(SYM_HEADER, headerBuffer->handle_);
503-
buffers->Set(SYM_ODD, oddBuffer->handle_);
504502

505503
target->Set(SYM_BUFFERS, buffers);
506504

0 commit comments

Comments
 (0)