Skip to content
Browse files

v0.1.10

 1. Build with debug information.
 2. Avoid unnecessary event emission.
  • Loading branch information...
1 parent b157081 commit fce09b1d16a17013f701d53feb976acc1b6b54f6 @egorich239 egorich239 committed Nov 10, 2010
Showing with 275 additions and 19 deletions.
  1. +6 −0 HISTORY
  2. +8 −7 README
  3. +3 −0 build.sh
  4. +22 −0 demo/bzstreams-demo.js
  5. +22 −0 demo/demo.js
  6. +22 −0 demo/streams-demo.js
  7. +34 −10 lib/compress/index.js
  8. +1 −1 package.json
  9. +22 −0 src/bzip.cc
  10. +23 −0 src/compress.cc
  11. +23 −0 src/gzip.cc
  12. +22 −0 src/utils.h
  13. +58 −0 src/zlib.h
  14. +9 −1 wscript
View
6 HISTORY
@@ -1,3 +1,9 @@
+2010-11-10 v0.1.10
+ * Don't emit data events on empty buffer.
+ * Debug build option in wscript.
+ * Minor documentation changes.
+ * Copyright notices.
+
2010-09-19 v0.1.9
* Fixed memory leak in Request destructor.
View
15 README
@@ -2,22 +2,23 @@ About
=====
Asynchronous streaming compression module for node.js.
-
Note, that API has changed since forked from original project by waveto. See
HISTORY for more details.
-
Currently library supports two compression backends: gzip and bzip2.
-
-To install, ensure that you have libz and libbz2 installed, and run:
+To install, ensure that you have libz and libbz2 installed.
Build
=====
-node-waf configure
-node-waf build
+$ gcc --version
+gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
+
+$ node-waf configure
+$ node-waf build
Configuration options:
+ --debug Build with debug information.
--with-gzip Build with gzip support. Default.
--no-gzip Build w/o gzip support.
--with-bzip Build with bzip support.
@@ -27,7 +28,7 @@ Build puts the compress-bindings.node binary module in build/default.
Usage examples
---------------
+==============
See demo/demo.js.
View
3 build.sh
@@ -1,4 +1,7 @@
#!/bin/sh
+#
+# Author: Ivan Egorov (egorich.3.04@gmail.com).
+#
node-waf configure $*
node-waf build
View
22 demo/bzstreams-demo.js
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
var compress=require("../lib/compress");
var sys=require("sys");
var posix=require("fs");
View
22 demo/demo.js
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
var compress=require("../lib/compress");
var events=require('events');
var sys=require("sys");
View
22 demo/streams-demo.js
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
var compress=require("../lib/compress");
var sys=require("sys");
var posix=require("fs");
View
44 lib/compress/index.js
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
var events = require('events');
var Buffer = require('buffer').Buffer;
var assert = require('assert');
@@ -187,19 +209,21 @@ CommonStream.prototype.emitEvent_ = function(err, data, fin) {
return;
}
- if (this.outputEncoding_ != 'binary') {
- var str = data;
- var len = Buffer.byteLength(str, 'binary');
- data = new Buffer(len);
- if (len > 0) {
- data.write(str, 'binary', 0);
- }
+ if (data.length != 0) {
+ if (this.outputEncoding_ != 'binary') {
+ var str = data;
+ var len = Buffer.byteLength(str, 'binary');
+ data = new Buffer(len);
+ if (len > 0) {
+ data.write(str, 'binary', 0);
+ }
- if (this.outputEncoding_ != null) {
- data = data.toString(this.outputEncoding_, 0, data.length);
+ if (this.outputEncoding_ != null) {
+ data = data.toString(this.outputEncoding_, 0, data.length);
+ }
}
+ this.dataQueue_.push(data);
}
- this.dataQueue_.push(data);
if (fin) {
this.dataQueue_.push(null);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "compress",
"description": "A streaming compression for node.js",
- "version": "0.1.9",
+ "version": "0.1.10",
"author": "Ivan Egorov",
"repository": {
"type": "git",
View
22 src/bzip.cc
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
#include <node.h>
#include <node_events.h>
#include <assert.h>
View
23 src/compress.cc
@@ -1,3 +1,26 @@
+/*
+ * Copyright 2009, Acknack Ltd. All rights reserved.
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
#include <node.h>
#ifdef WITH_GZIP
View
23 src/gzip.cc
@@ -1,3 +1,26 @@
+/*
+ * Copyright 2009, Acknack Ltd. All rights reserved.
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
#include <node.h>
#include <node_events.h>
#include <node_buffer.h>
View
22 src/utils.h
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
#ifndef NODE_COMPRESS_UTILS_H__
#define NODE_COMPRESS_UTILS_H__
View
58 src/zlib.h
@@ -1,3 +1,25 @@
+/*
+ * Copyright 2010, Ivan Egorov (egorich.3.04@gmail.com).
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
#ifndef NODE_COMPRESS_ZLIB_H__
#define NODE_COMPRESS_ZLIB_H__
@@ -13,6 +35,24 @@
#include "utils.h"
+
+#ifdef DEBUG
+
+#include <stdio.h>
+
+#define DEBUG_P(fmt, args...) \
+ do { \
+ fprintf(stderr, "%s: %d %s " fmt "\n", \
+ __FILE__, __LINE__, __PRETTY_FUNCTION__, ##args); \
+ } while (0);
+
+
+#else
+
+#define DEBUG_P(fmt, args...)
+
+#endif
+
using namespace v8;
using namespace node;
@@ -76,14 +116,17 @@ class ZipLib : ObjectWrap {
public:
static Request* Write(Self *self, Local<Value> inputBuffer,
Local<Function> callback) {
+ DEBUG_P("WRITE");
return new(std::nothrow) Request(self, inputBuffer, callback);
}
static Request* Close(Self *self, Local<Function> callback) {
+ DEBUG_P("CLOSE");
return new(std::nothrow) Request(self, callback);
}
static Request* Destroy(Self *self) {
+ DEBUG_P("DESTROY");
return new(std::nothrow) Request(self);
}
@@ -260,6 +303,7 @@ class ZipLib : ObjectWrap {
processorActive_ = true;
}
pthread_mutex_unlock(&requestsMutex_);
+ DEBUG_P("PUSH: startProcessing = %d", startProcessing);
if (!pushed) {
return ThrowGentleOom();
@@ -270,8 +314,13 @@ class ZipLib : ObjectWrap {
Self::DoHandleCallbacks, request);
}
+ DEBUG_P("ev_ref()");
ev_ref(EV_DEFAULT_UC);
+ DEBUG_P(" ev_ref() done");
+
+ DEBUG_P("Ref()");
Ref();
+ DEBUG_P(" Ref() done");
return Undefined();
}
@@ -289,6 +338,7 @@ class ZipLib : ObjectWrap {
volatile bool flag;
do {
while (ReentrantPop(requestsQueue_, requestsMutex_, request)) {
+ DEBUG_P("POP: kind = %d", request->kind());
switch (request->kind()) {
case Request::RWrite:
request->setStatus(
@@ -312,12 +362,16 @@ class ZipLib : ObjectWrap {
ev_async_send(EV_DEFAULT_UC_ &callbackNotify_);
// Unref counter triggered by request.
+ DEBUG_P("ev_unref() ...");
ev_unref(EV_DEFAULT_UC);
+ DEBUG_P(" ev_unref() done");
if (!success) {
// Normally we should unref self() after callback called in
// DoHandleCallbacks(), but as we failed to push request for
// callback for this request, we should unref here.
+ DEBUG_P("request->self()->Unref()");
request->self()->Unref();
+ DEBUG_P(" request->self()->Unref() done");
}
}
@@ -334,11 +388,15 @@ class ZipLib : ObjectWrap {
static int DoHandleCallbacks(eio_req *req) {
Request *request;
while (ReentrantPop(callbackQueue_, callbackMutex_, request)) {
+ DEBUG_P("CALLBACK");
+
Self *self = request->self();
self->DoCallback(request->callback(),
request->status(), request->output());
+ DEBUG_P("self->Unref()");
self->Unref();
+ DEBUG_P(" self->Unref() done");
delete request;
}
return 0;
View
10 wscript
@@ -4,11 +4,12 @@ from os.path import exists
srcdir = "."
blddir = "build"
-VERSION = "0.1.9"
+VERSION = "0.1.10"
def set_options(opt):
opt.tool_options("compiler_cxx")
+ opt.add_option('--debug', dest='debug', action='store_true', default=False)
opt.add_option('--with-gzip', dest='gzip', action='store_true', default=True)
opt.add_option('--no-gzip', dest='gzip', action='store_false')
opt.add_option('--with-bzip', dest='bzip', action='store_true', default=False)
@@ -35,6 +36,13 @@ def configure(conf):
conf.env.DEFINES += [ 'WITH_BZIP' ]
conf.env.USELIB += [ 'BZLIB' ]
+ if Options.options.debug:
+ conf.env.DEFINES += [ 'DEBUG' ]
+ conf.env.CXXFLAGS = [ '-O0', '-g3' ]
+ else:
+ conf.env.CXXFLAGS = [ '-O2' ]
+
+
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
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.