Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

v0.1.10

 1. Build with debug information.
 2. Avoid unnecessary event emission.
  • Loading branch information...
commit fce09b1d16a17013f701d53feb976acc1b6b54f6 1 parent b157081
Ivan Egorov egorich239 authored
6 HISTORY
... ... @@ -1,3 +1,9 @@
  1 +2010-11-10 v0.1.10
  2 + * Don't emit data events on empty buffer.
  3 + * Debug build option in wscript.
  4 + * Minor documentation changes.
  5 + * Copyright notices.
  6 +
1 7 2010-09-19 v0.1.9
2 8 * Fixed memory leak in Request destructor.
3 9
15 README
@@ -2,22 +2,23 @@ About
2 2 =====
3 3
4 4 Asynchronous streaming compression module for node.js.
5   -
6 5 Note, that API has changed since forked from original project by waveto. See
7 6 HISTORY for more details.
8   -
9 7 Currently library supports two compression backends: gzip and bzip2.
10   -
11   -To install, ensure that you have libz and libbz2 installed, and run:
  8 +To install, ensure that you have libz and libbz2 installed.
12 9
13 10
14 11 Build
15 12 =====
16 13
17   -node-waf configure
18   -node-waf build
  14 +$ gcc --version
  15 +gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
  16 +
  17 +$ node-waf configure
  18 +$ node-waf build
19 19
20 20 Configuration options:
  21 + --debug Build with debug information.
21 22 --with-gzip Build with gzip support. Default.
22 23 --no-gzip Build w/o gzip support.
23 24 --with-bzip Build with bzip support.
@@ -27,7 +28,7 @@ Build puts the compress-bindings.node binary module in build/default.
27 28
28 29
29 30 Usage examples
30   ---------------
  31 +==============
31 32
32 33 See demo/demo.js.
33 34
3  build.sh
... ... @@ -1,4 +1,7 @@
1 1 #!/bin/sh
  2 +#
  3 +# Author: Ivan Egorov (egorich.3.04@gmail.com).
  4 +#
2 5
3 6 node-waf configure $*
4 7 node-waf build
22 demo/bzstreams-demo.js
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 var compress=require("../lib/compress");
2 24 var sys=require("sys");
3 25 var posix=require("fs");
22 demo/demo.js
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 var compress=require("../lib/compress");
2 24 var events=require('events');
3 25 var sys=require("sys");
22 demo/streams-demo.js
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 var compress=require("../lib/compress");
2 24 var sys=require("sys");
3 25 var posix=require("fs");
44 lib/compress/index.js
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 var events = require('events');
2 24 var Buffer = require('buffer').Buffer;
3 25 var assert = require('assert');
@@ -187,19 +209,21 @@ CommonStream.prototype.emitEvent_ = function(err, data, fin) {
187 209 return;
188 210 }
189 211
190   - if (this.outputEncoding_ != 'binary') {
191   - var str = data;
192   - var len = Buffer.byteLength(str, 'binary');
193   - data = new Buffer(len);
194   - if (len > 0) {
195   - data.write(str, 'binary', 0);
196   - }
  212 + if (data.length != 0) {
  213 + if (this.outputEncoding_ != 'binary') {
  214 + var str = data;
  215 + var len = Buffer.byteLength(str, 'binary');
  216 + data = new Buffer(len);
  217 + if (len > 0) {
  218 + data.write(str, 'binary', 0);
  219 + }
197 220
198   - if (this.outputEncoding_ != null) {
199   - data = data.toString(this.outputEncoding_, 0, data.length);
  221 + if (this.outputEncoding_ != null) {
  222 + data = data.toString(this.outputEncoding_, 0, data.length);
  223 + }
200 224 }
  225 + this.dataQueue_.push(data);
201 226 }
202   - this.dataQueue_.push(data);
203 227
204 228 if (fin) {
205 229 this.dataQueue_.push(null);
2  package.json
... ... @@ -1,7 +1,7 @@
1 1 {
2 2 "name": "compress",
3 3 "description": "A streaming compression for node.js",
4   - "version": "0.1.9",
  4 + "version": "0.1.10",
5 5 "author": "Ivan Egorov",
6 6 "repository": {
7 7 "type": "git",
22 src/bzip.cc
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 #include <node.h>
2 24 #include <node_events.h>
3 25 #include <assert.h>
23 src/compress.cc
... ... @@ -1,3 +1,26 @@
  1 +/*
  2 + * Copyright 2009, Acknack Ltd. All rights reserved.
  3 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  4 + *
  5 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  6 + * of this software and associated documentation files (the "Software"), to
  7 + * deal in the Software without restriction, including without limitation the
  8 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9 + * sell copies of the Software, and to permit persons to whom the Software is
  10 + * furnished to do so, subject to the following conditions:
  11 + *
  12 + * The above copyright notice and this permission notice shall be included in
  13 + * all copies or substantial portions of the Software.
  14 + *
  15 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21 + * IN THE SOFTWARE.
  22 + */
  23 +
1 24 #include <node.h>
2 25
3 26 #ifdef WITH_GZIP
23 src/gzip.cc
... ... @@ -1,3 +1,26 @@
  1 +/*
  2 + * Copyright 2009, Acknack Ltd. All rights reserved.
  3 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  4 + *
  5 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  6 + * of this software and associated documentation files (the "Software"), to
  7 + * deal in the Software without restriction, including without limitation the
  8 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9 + * sell copies of the Software, and to permit persons to whom the Software is
  10 + * furnished to do so, subject to the following conditions:
  11 + *
  12 + * The above copyright notice and this permission notice shall be included in
  13 + * all copies or substantial portions of the Software.
  14 + *
  15 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21 + * IN THE SOFTWARE.
  22 + */
  23 +
1 24 #include <node.h>
2 25 #include <node_events.h>
3 26 #include <node_buffer.h>
22 src/utils.h
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 #ifndef NODE_COMPRESS_UTILS_H__
2 24 #define NODE_COMPRESS_UTILS_H__
3 25
58 src/zlib.h
... ... @@ -1,3 +1,25 @@
  1 +/*
  2 + * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
  3 + *
  4 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  5 + * of this software and associated documentation files (the "Software"), to
  6 + * deal in the Software without restriction, including without limitation the
  7 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8 + * sell copies of the Software, and to permit persons to whom the Software is
  9 + * furnished to do so, subject to the following conditions:
  10 + *
  11 + * The above copyright notice and this permission notice shall be included in
  12 + * all copies or substantial portions of the Software.
  13 + *
  14 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20 + * IN THE SOFTWARE.
  21 + */
  22 +
1 23 #ifndef NODE_COMPRESS_ZLIB_H__
2 24 #define NODE_COMPRESS_ZLIB_H__
3 25
@@ -13,6 +35,24 @@
13 35
14 36 #include "utils.h"
15 37
  38 +
  39 +#ifdef DEBUG
  40 +
  41 +#include <stdio.h>
  42 +
  43 +#define DEBUG_P(fmt, args...) \
  44 + do { \
  45 + fprintf(stderr, "%s: %d %s " fmt "\n", \
  46 + __FILE__, __LINE__, __PRETTY_FUNCTION__, ##args); \
  47 + } while (0);
  48 +
  49 +
  50 +#else
  51 +
  52 +#define DEBUG_P(fmt, args...)
  53 +
  54 +#endif
  55 +
16 56 using namespace v8;
17 57 using namespace node;
18 58
@@ -76,14 +116,17 @@ class ZipLib : ObjectWrap {
76 116 public:
77 117 static Request* Write(Self *self, Local<Value> inputBuffer,
78 118 Local<Function> callback) {
  119 + DEBUG_P("WRITE");
79 120 return new(std::nothrow) Request(self, inputBuffer, callback);
80 121 }
81 122
82 123 static Request* Close(Self *self, Local<Function> callback) {
  124 + DEBUG_P("CLOSE");
83 125 return new(std::nothrow) Request(self, callback);
84 126 }
85 127
86 128 static Request* Destroy(Self *self) {
  129 + DEBUG_P("DESTROY");
87 130 return new(std::nothrow) Request(self);
88 131 }
89 132
@@ -260,6 +303,7 @@ class ZipLib : ObjectWrap {
260 303 processorActive_ = true;
261 304 }
262 305 pthread_mutex_unlock(&requestsMutex_);
  306 + DEBUG_P("PUSH: startProcessing = %d", startProcessing);
263 307
264 308 if (!pushed) {
265 309 return ThrowGentleOom();
@@ -270,8 +314,13 @@ class ZipLib : ObjectWrap {
270 314 Self::DoHandleCallbacks, request);
271 315 }
272 316
  317 + DEBUG_P("ev_ref()");
273 318 ev_ref(EV_DEFAULT_UC);
  319 + DEBUG_P(" ev_ref() done");
  320 +
  321 + DEBUG_P("Ref()");
274 322 Ref();
  323 + DEBUG_P(" Ref() done");
275 324 return Undefined();
276 325 }
277 326
@@ -289,6 +338,7 @@ class ZipLib : ObjectWrap {
289 338 volatile bool flag;
290 339 do {
291 340 while (ReentrantPop(requestsQueue_, requestsMutex_, request)) {
  341 + DEBUG_P("POP: kind = %d", request->kind());
292 342 switch (request->kind()) {
293 343 case Request::RWrite:
294 344 request->setStatus(
@@ -312,12 +362,16 @@ class ZipLib : ObjectWrap {
312 362 ev_async_send(EV_DEFAULT_UC_ &callbackNotify_);
313 363
314 364 // Unref counter triggered by request.
  365 + DEBUG_P("ev_unref() ...");
315 366 ev_unref(EV_DEFAULT_UC);
  367 + DEBUG_P(" ev_unref() done");
316 368 if (!success) {
317 369 // Normally we should unref self() after callback called in
318 370 // DoHandleCallbacks(), but as we failed to push request for
319 371 // callback for this request, we should unref here.
  372 + DEBUG_P("request->self()->Unref()");
320 373 request->self()->Unref();
  374 + DEBUG_P(" request->self()->Unref() done");
321 375 }
322 376 }
323 377
@@ -334,11 +388,15 @@ class ZipLib : ObjectWrap {
334 388 static int DoHandleCallbacks(eio_req *req) {
335 389 Request *request;
336 390 while (ReentrantPop(callbackQueue_, callbackMutex_, request)) {
  391 + DEBUG_P("CALLBACK");
  392 +
337 393 Self *self = request->self();
338 394 self->DoCallback(request->callback(),
339 395 request->status(), request->output());
340 396
  397 + DEBUG_P("self->Unref()");
341 398 self->Unref();
  399 + DEBUG_P(" self->Unref() done");
342 400 delete request;
343 401 }
344 402 return 0;
10 wscript
@@ -4,11 +4,12 @@ from os.path import exists
4 4
5 5 srcdir = "."
6 6 blddir = "build"
7   -VERSION = "0.1.9"
  7 +VERSION = "0.1.10"
8 8
9 9 def set_options(opt):
10 10 opt.tool_options("compiler_cxx")
11 11
  12 + opt.add_option('--debug', dest='debug', action='store_true', default=False)
12 13 opt.add_option('--with-gzip', dest='gzip', action='store_true', default=True)
13 14 opt.add_option('--no-gzip', dest='gzip', action='store_false')
14 15 opt.add_option('--with-bzip', dest='bzip', action='store_true', default=False)
@@ -35,6 +36,13 @@ def configure(conf):
35 36 conf.env.DEFINES += [ 'WITH_BZIP' ]
36 37 conf.env.USELIB += [ 'BZLIB' ]
37 38
  39 + if Options.options.debug:
  40 + conf.env.DEFINES += [ 'DEBUG' ]
  41 + conf.env.CXXFLAGS = [ '-O0', '-g3' ]
  42 + else:
  43 + conf.env.CXXFLAGS = [ '-O2' ]
  44 +
  45 +
38 46 def build(bld):
39 47 obj = bld.new_task_gen("cxx", "shlib", "node_addon")
40 48 obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]

0 comments on commit fce09b1

Please sign in to comment.
Something went wrong with that request. Please try again.