Browse files

compress/uncompress/isValidCompressed are now async, with synchronous…

… versions aswell.
  • Loading branch information...
1 parent abc2a93 commit 8018dc950d2e78b6738005c63917e3c07cd24fae @kesla committed Apr 19, 2011
Showing with 396 additions and 184 deletions.
  1. +2 −1 Readme.md
  2. +139 −25 binding.cc
  3. +78 −0 binding.h
  4. +47 −32 snappy.coffee
  5. +128 −125 test.coffee
  6. +2 −1 wscript
View
3 Readme.md
@@ -17,7 +17,8 @@ Snappy is widely used inside Google, in everything from BigTable and MapReduce t
# Examples
## String
snappy = require('./snappy');
- snappy.compress('string to compress', function(err, compressed){
+ // Use synchronous version
+ snappy.compressSync('string to compress', function(err, compressed){
// result will be string instead of Buffer
snappy.decompress(compressed, snappy.parsers.string, function(err, result){
console.log(result);
View
164 binding.cc
@@ -18,21 +18,44 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#include "./binding.h"
-#include <string>
-
-#include <node.h>
#include <node_buffer.h>
#include <snappy.h>
-#include <v8.h>
-namespace {
+#include <string.h> // memcpy
+
+namespace nodesnappy {
+// Request used in the async versions, used to store the data
+template<class T> struct SnappyRequest {
+ std::string input;
+ T result;
+ v8::Persistent<v8::Function> callback;
+};
+
+// CompressUncompressBinding
+// PROTECTED
+int CompressUncompressBase::After(eio_req *req) {
+ v8::HandleScope scope;
+ SnappyRequest<std::string>* snappy_request =
+ static_cast<SnappyRequest<std::string>*>(req->data);
+ v8::Local<v8::Value> argv[2];
+ argv[0] = v8::Local<v8::Value>::New(v8::Null());
+ argv[1] = CreateBuffer(snappy_request->result);
+ snappy_request->callback->Call(v8::Context::GetCurrent()->Global(), 2, argv);
+ ev_unref(EV_DEFAULT_UC);
+ snappy_request->callback.Dispose();
+ delete snappy_request;
+ return 0;
+}
+
// Create a node-buffer, as described in
// http://sambro.is-super-awesome.com/2011/03/03/creating-a-proper-buffer-in-a-node-c-addon/
-inline v8::Local<v8::Object> CreateBuffer(std::string str) {
+inline v8::Local<v8::Object>
+CompressUncompressBase::CreateBuffer(const std::string& str) {
size_t length = str.length();
- char* ptr = &*str.begin();
- node::Buffer *slowBuffer = node::Buffer::New(ptr, length);
+ node::Buffer *slowBuffer = node::Buffer::New(length);
+ memcpy(node::Buffer::Data(slowBuffer), str.data(), length);
v8::Local<v8::Object> obj = v8::Context::GetCurrent()->Global();
v8::Local<v8::Function> bufferConstructor =
v8::Local<v8::Function>::Cast(obj->Get(v8::String::New("Buffer")));
@@ -41,12 +64,25 @@ inline v8::Local<v8::Object> CreateBuffer(std::string str) {
return bufferConstructor->NewInstance(3, constructorArgs);
}
-// Use snappy::Compress method, compress a buffer or a string and use callback
-// with the response
-v8::Handle<v8::Value> DoCompress(const v8::Arguments& args) {
+// CompressBinding
+// PUBLIC
+v8::Handle<v8::Value> CompressBinding::Async(const v8::Arguments& args) {
v8::HandleScope scope;
std::string dst;
+ SnappyRequest<std::string>* snappy_request = new SnappyRequest<std::string>();
v8::String::Utf8Value data(args[0]->ToString());
+ v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
+ snappy_request->callback = v8::Persistent<v8::Function>::New(callback);
+ snappy_request->input = std::string(*data, data.length());
+ eio_custom(AsyncOperation, EIO_PRI_DEFAULT, After, snappy_request);
+ ev_ref(EV_DEFAULT_UC);
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> CompressBinding::Sync(const v8::Arguments& args) {
+ v8::HandleScope scope;
+ v8::String::Utf8Value data(args[0]->ToString());
+ std::string dst;
snappy::Compress(*data, data.length(), &dst);
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
v8::Local<v8::Value> argv[2];
@@ -56,40 +92,118 @@ v8::Handle<v8::Value> DoCompress(const v8::Arguments& args) {
return scope.Close(v8::Undefined());
}
-// Use snappy::IsValidCompressedBuffer method and use callback with response.
-// return true if a buffer or a string is valid compressed
-v8::Handle<v8::Value> DoIsValidCompressed(const v8::Arguments& args) {
+// PRIVATE
+int CompressBinding::AsyncOperation(eio_req *req) {
+ SnappyRequest<std::string>* snappy_request =
+ static_cast<SnappyRequest<std::string>*>(req->data);
+ std::string dst;
+ std::string* input = &snappy_request->input;
+ snappy::Compress(input->data(), input->length(), &dst);
+ snappy_request->result = dst;
+ return 0;
+}
+
+// UncompressBinding
+// PUBLIC
+v8::Handle<v8::Value> UncompressBinding::Async(const v8::Arguments& args) {
v8::HandleScope scope;
+ std::string dst;
v8::String::Utf8Value data(args[0]->ToString());
- bool valid = snappy::IsValidCompressedBuffer(*data, data.length());
+ SnappyRequest<std::string>* snappy_request = new SnappyRequest<std::string>();
+ v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
+ snappy_request->callback = v8::Persistent<v8::Function>::New(callback);
+ snappy_request->input = std::string(*data, data.length());
+ eio_custom(AsyncOperation, EIO_PRI_DEFAULT, After, snappy_request);
+ ev_ref(EV_DEFAULT_UC);
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> UncompressBinding::Sync(const v8::Arguments& args) {
+ v8::HandleScope scope;
+ std::string dst;
+ v8::String::Utf8Value data(args[0]->ToString());
+ snappy::Uncompress(*data, data.length(), &dst);
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
v8::Local<v8::Value> argv[2];
argv[0] = v8::Local<v8::Value>::New(v8::Null());
- argv[1] = v8::Local<v8::Boolean>::New(v8::Boolean::New(valid));
+ argv[1] = CreateBuffer(dst);
callback->Call(v8::Context::GetCurrent()->Global(), 2, argv);
return scope.Close(v8::Undefined());
}
-// Use snappy::Uncompress method, uncompress a buffer or a string and use
-// callback with the response
-v8::Handle<v8::Value> DoUncompress(const v8::Arguments& args) {
+// PRIVATE
+int UncompressBinding::AsyncOperation(eio_req *req) {
+ SnappyRequest<std::string>* snappy_request =
+ static_cast<SnappyRequest<std::string>*>(req->data);
+ std::string dst;
+ std::string* input = &snappy_request->input;
+ snappy::Uncompress(input->data(), input->length(), &dst);
+ snappy_request->result = dst;
+ return 0;
+}
+
+// IsValidCompressedBinding
+// PUBLIC
+v8::Handle<v8::Value>
+IsValidCompressedBinding::Async(const v8::Arguments& args) {
v8::HandleScope scope;
std::string dst;
v8::String::Utf8Value data(args[0]->ToString());
- snappy::Uncompress(*data, data.length(), &dst);
+ SnappyRequest<bool>* snappy_request = new SnappyRequest<bool>();
+ v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
+ snappy_request->callback = v8::Persistent<v8::Function>::New(callback);
+ snappy_request->input = std::string(*data, data.length());
+ eio_custom(AsyncOperation, EIO_PRI_DEFAULT, After, snappy_request);
+ ev_ref(EV_DEFAULT_UC);
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value>
+IsValidCompressedBinding::Sync(const v8::Arguments& args) {
+ v8::HandleScope scope;
+ std::string dst;
+ v8::String::Utf8Value data(args[0]->ToString());
+ bool valid = snappy::IsValidCompressedBuffer(*data, data.length());
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
v8::Local<v8::Value> argv[2];
argv[0] = v8::Local<v8::Value>::New(v8::Null());
- argv[1] = CreateBuffer(dst);
+ argv[1] = v8::Local<v8::Value>::New(v8::Boolean::New(valid));
callback->Call(v8::Context::GetCurrent()->Global(), 2, argv);
return scope.Close(v8::Undefined());
}
+// PRIVATE
+int IsValidCompressedBinding::After(eio_req *req) {
+ v8::HandleScope scope;
+ SnappyRequest<bool>* snappy_request =
+ static_cast<SnappyRequest<bool>*>(req->data);
+ v8::Local<v8::Value> argv[2];
+ argv[0] = v8::Local<v8::Value>::New(v8::Null());
+ argv[1] = v8::Local<v8::Value>::New(v8::Boolean::New(snappy_request->result));
+ snappy_request->callback->Call(v8::Context::GetCurrent()->Global(), 2, argv);
+ ev_unref(EV_DEFAULT_UC);
+ snappy_request->callback.Dispose();
+ delete snappy_request;
+ return 0;
+}
+
+int IsValidCompressedBinding::AsyncOperation(eio_req *req) {
+ SnappyRequest<bool>* snappy_request = (SnappyRequest<bool>*) req->data;
+ std::string* input = &snappy_request->input;
+ snappy_request->result =
+ snappy::IsValidCompressedBuffer(input->data(), input->length());
+ return 0;
+}
+
extern "C" void
init(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
- NODE_SET_METHOD(target, "compress", DoCompress);
- NODE_SET_METHOD(target, "uncompress", DoUncompress);
- NODE_SET_METHOD(target, "isValidCompressed", DoIsValidCompressed);
+ NODE_SET_METHOD(target, "compress", CompressBinding::Async);
+ NODE_SET_METHOD(target, "compressSync", CompressBinding::Sync);
+ NODE_SET_METHOD(target, "uncompress", UncompressBinding::Async);
+ NODE_SET_METHOD(target, "uncompressSync", UncompressBinding::Sync);
+ NODE_SET_METHOD(target, "isValidCompressed", IsValidCompressedBinding::Async);
+ NODE_SET_METHOD(target, "isValidCompressedSync",
+ IsValidCompressedBinding::Sync);
}
-} // namespace
+} // namespace nodesnappy
View
78 binding.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2011 David Björklund
+//
+// 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_SNAPPY_BINDING_H__
+#define __NODE_SNAPPY_BINDING_H__
+#include <node.h>
+#include <v8.h>
+#include <string>
+
+namespace nodesnappy {
+
+// Base class for both compress and uncompress including shared methods
+class CompressUncompressBase {
+ protected:
+ static int After(eio_req *req);
+ static v8::Local<v8::Object> CreateBuffer(const std::string&);
+};
+
+// Bindings to the snappy::Compress-method. Includes both asynchronous
+// and synchronous bindings
+class CompressBinding : CompressUncompressBase {
+ public:
+ // Asynchronous binding
+ static v8::Handle<v8::Value> Async(const v8::Arguments& args);
+ // Synchronous binding
+ static v8::Handle<v8::Value> Sync(const v8::Arguments& args);
+
+ private:
+ static int AsyncOperation(eio_req *req);
+};
+
+// Bindings to the snappy::Uncompress-method. Includes both asynchronous
+// and synchronous bindings
+class UncompressBinding : CompressUncompressBase {
+ public:
+ // Asynchronous binding
+ static v8::Handle<v8::Value> Async(const v8::Arguments& args);
+ // Synchronous binding
+ static v8::Handle<v8::Value> Sync(const v8::Arguments& args);
+
+ private:
+ static int AsyncOperation(eio_req *req);
+};
+
+// Bindings to the snappy::IsValidCompressedBuffer-method. Includes both
+// asynchronous and synchronous bindings
+class IsValidCompressedBinding {
+ public:
+ // Asynchronous binding
+ static v8::Handle<v8::Value> Async(const v8::Arguments& args);
+ // Synchronous binding
+ static v8::Handle<v8::Value> Sync(const v8::Arguments& args);
+
+ private:
+ static int After(eio_req *req);
+ static int AsyncOperation(eio_req *req);
+};
+
+} // namespace nodesnappy
+
+#endif /* __NODE_SNAPPY_BINDING_H__ */
View
79 snappy.coffee
@@ -1,48 +1,63 @@
###
-Copyright (c) 2011 David Björklund
-
-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.
+ Copyright (c) 2011 David Björklund
+
+ 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.
###
binding = require('./build/default/binding')
+# Parsers
+exports.parsers =
+ json: (buffer) ->
+ return JSON.parse buffer
+ string: (buffer) ->
+ return buffer.toString("utf8")
+ raw: (buffer)->
+ return buffer
+
+# Compress
exports.compress = (input, callback) ->
- unless typeof input is 'string' or Buffer.isBuffer input
- input = JSON.stringify(input)
- binding.compress(input, callback)
+ unless typeof input is 'string' or Buffer.isBuffer input
+ input = JSON.stringify(input)
+ binding.compress(input, callback)
+
+exports.compressSync = (input, callback) ->
+ unless typeof input is 'string' or Buffer.isBuffer input
+ input = JSON.stringify(input)
+ binding.compressSync(input, callback)
+# isValidCompressed
exports.isValidCompressed = (input, callback) ->
binding.isValidCompressed(input, callback)
-exports.parsers =
- json: (buffer) ->
- return JSON.parse buffer
-
- string: (buffer) ->
- return buffer.toString("utf8")
-
- raw: (buffer)->
- return buffer
+exports.isValidCompressedSync = (input, callback) ->
+ binding.isValidCompressedSync(input, callback)
+# de-/uncompress
exports.uncompress = (compressed, callback, parse = @parsers.raw) ->
binding.uncompress(compressed, (err, data) ->
callback(err, parse(data))
)
-
exports.decompress = exports.uncompress
+
+exports.uncompressSync = (compressed, callback, parse = @parsers.raw) ->
+ binding.uncompressSync(compressed, (err, data) ->
+ callback(err, parse(data))
+ )
+exports.decompressSync = exports.uncompressSync
View
253 test.coffee
@@ -31,135 +31,138 @@ string = "foo foo foo Fasfa daos asd foo foo foo asdasf bar bar aarr"
buffer = new Buffer(string)
json = {"foo" : "bar", "fou" : 0, "shou" : "ho ho", "what?" : ["hey", "you"]}
-vows.describe('snappy').addBatch(
- "A buffer":
- "compressed":
- topic: () -> snappy.compress(buffer, @callback)
- 'should not have errors': (err, compressed) ->
- assert.isNull err
-
- 'should result in a buffer': (err, compressed) ->
- assert.isBuffer compressed
-
- 'and tested if valid':
- topic: (compressed) -> snappy.isValidCompressed(compressed, @callback)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in true': (err, result) ->
- assert.isTrue result
-
- 'and decompressed with string-parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback, snappy.parsers.string)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in a string': (err, result) ->
- assert.isString result
-
- 'should equal the original when parsed': (err, result) ->
- assert.strictEqual result, buffer.toString("utf8")
-
- 'and decompressed without any parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in a buffer': (err, result) ->
- assert.isBuffer result
-
- 'should equal the original': (err, result) ->
- assert.strictEqual result.toString("utf8"), buffer.toString("utf8")
-
- "A json-object":
- "compressed":
- topic: () -> snappy.compress(json, @callback)
- 'should not have errors': (err, compressed) ->
- assert.isNull err
-
- 'should result in a buffer': (err, compressed) ->
- assert.isBuffer compressed
-
- 'and tested if valid':
- topic: (compressed) -> snappy.isValidCompressed(compressed, @callback)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in true': (err, result) ->
- assert.isTrue result
-
- 'and decompressed with json-parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback, snappy.parsers.json)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in json': (err, result) ->
- # TODO: Fix proper test
- assert.instanceOf result, Object
-
- 'should equal the original': (err, result) ->
- assert.deepEqual result, json
-
- 'and decompressed with string-parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback, snappy.parsers.string)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in a string': (err, result) ->
- assert.isString result
-
- 'should equal the original when parsed': (err, result) ->
- assert.deepEqual JSON.parse(result), json
-
- 'and decompressed without any parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback)
- 'should not have errors': (err, result) ->
- assert.isNull err
-
- 'should result in a buffer': (err, result) ->
- assert.isBuffer result
-
- 'should equal the original when parsed': (err, result) ->
- assert.deepEqual JSON.parse(result), json
-
- "A string":
- "compressed":
- topic: () -> snappy.compress(string, @callback)
- 'should not have errors': (err, compressed) ->
- assert.isNull err
- 'should result in a buffer': (err, compressed) ->
- assert.isBuffer compressed
-
- 'and tested if valid':
- topic: (compressed) -> snappy.isValidCompressed(compressed, @callback)
- 'should not have errors': (err, result) ->
+for sync in ["", "Sync"]
+ title = if sync is "" then "asyncronous" else "synchronous"
+ vows.describe("snappy (#{title} versions)").addBatch(
+ "A buffer":
+ "compressed":
+ topic: () -> snappy["compress#{sync}"](buffer, @callback)
+ 'should not have errors': (err, compressed) ->
assert.isNull err
-
- 'should result in true': (err, result) ->
- assert.isTrue result
- 'and decompressed with string-parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback, snappy.parsers.string)
- 'should not have errors': (err, result) ->
+ 'should result in a buffer': (err, compressed) ->
+ assert.isBuffer compressed
+
+ 'and tested if valid':
+ topic: (compressed) -> snappy["isValidCompressed#{sync}"](compressed, @callback)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in true': (err, result) ->
+ assert.isTrue result
+
+ 'and decompressed with string-parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback, snappy.parsers.string)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in a string': (err, result) ->
+ assert.isString result
+
+ 'should equal the original when parsed': (err, result) ->
+ assert.strictEqual result, buffer.toString("utf8")
+
+ 'and decompressed without any parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in a buffer': (err, result) ->
+ assert.isBuffer result
+
+ 'should equal the original': (err, result) ->
+ assert.strictEqual result.toString("utf8"), buffer.toString("utf8")
+
+ "A json-object":
+ "compressed":
+ topic: () -> snappy["compress#{sync}"](json, @callback)
+ 'should not have errors': (err, compressed) ->
assert.isNull err
-
- 'should result in a string': (err, result) ->
- assert.isString result
-
- 'should equal the original': (err, result) ->
- assert.strictEqual result, string
- 'and decompressed without any parser':
- topic: (compressed) -> snappy.decompress(compressed, @callback)
- 'should not have errors': (err, result) ->
+ 'should result in a buffer': (err, compressed) ->
+ assert.isBuffer compressed
+
+ 'and tested if valid':
+ topic: (compressed) -> snappy["isValidCompressed#{sync}"](compressed, @callback)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in true': (err, result) ->
+ assert.isTrue result
+
+ 'and decompressed with json-parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback, snappy.parsers.json)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in json': (err, result) ->
+ # TODO: Fix proper test
+ assert.instanceOf result, Object
+
+ 'should equal the original': (err, result) ->
+ assert.deepEqual result, json
+
+ 'and decompressed with string-parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback, snappy.parsers.string)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in a string': (err, result) ->
+ assert.isString result
+
+ 'should equal the original when parsed': (err, result) ->
+ assert.deepEqual JSON.parse(result), json
+
+ 'and decompressed without any parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in a buffer': (err, result) ->
+ assert.isBuffer result
+
+ 'should equal the original when parsed': (err, result) ->
+ assert.deepEqual JSON.parse(result), json
+
+ "A string":
+ "compressed":
+ topic: () -> snappy["compress#{sync}"](string, @callback)
+ 'should not have errors': (err, compressed) ->
assert.isNull err
-
- 'should result in a buffer': (err, result) ->
- assert.isBuffer result
-
- 'should equal the original when parsed': (err, result) ->
- string2 = result.toString("utf8")
- assert.strictEqual string2, string
-).export(module)
+ 'should result in a buffer': (err, compressed) ->
+ assert.isBuffer compressed
+
+ 'and tested if valid':
+ topic: (compressed) -> snappy["isValidCompressed#{sync}"](compressed, @callback)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in true': (err, result) ->
+ assert.isTrue result
+
+ 'and decompressed with string-parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback, snappy.parsers.string)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in a string': (err, result) ->
+ assert.isString result
+
+ 'should equal the original': (err, result) ->
+ assert.strictEqual result, string
+
+ 'and decompressed without any parser':
+ topic: (compressed) -> snappy["decompress#{sync}"](compressed, @callback)
+ 'should not have errors': (err, result) ->
+ assert.isNull err
+
+ 'should result in a buffer': (err, result) ->
+ assert.isBuffer result
+
+ 'should equal the original when parsed': (err, result) ->
+ string2 = result.toString("utf8")
+ assert.strictEqual string2, string
+
+ ).export(module)
View
3 wscript
@@ -40,7 +40,8 @@ def configure(conf):
def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
obj.uselib = "SNAPPY"
- obj.cxxflags = ['-Wall']
+ # -D_FILE_OFFSET_BITS and -D_LARGEFILE_SOURCE needed for libeio
+ obj.cxxflags = ['-Wall', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE']
obj.target = 'binding'
obj.source = 'binding.cc'
obj.install_path = None

0 comments on commit 8018dc9

Please sign in to comment.