Comparing version 3.0.8 to 3.1.0
@@ -5,3 +5,3 @@ { | ||
"description": "Nodejs bindings to Google's Snappy compression library", | ||
"version": "3.0.8", | ||
"version": "3.1.0", | ||
"homepage": "https://github.com/kesla/node-snappy", | ||
@@ -8,0 +8,0 @@ "repository": { |
# snappy [![Linux Status](https://img.shields.io/travis/kesla/node-snappy.svg?label=linux)](https://travis-ci.org/kesla/node-snappy) [![Windows Status](https://img.shields.io/appveyor/ci/kesla/node-snappy.svg?label=windows)](https://ci.appveyor.com/project/kesla/node-snappy) | ||
Nodejs bindings to the [snappy](github.com/google/snappy) compression library | ||
Nodejs bindings to the [snappy](https://github.com/google/snappy) compression library | ||
@@ -47,2 +47,6 @@ [![NPM](https://nodei.co/npm/snappy.png?downloads&stars)](https://nodei.co/npm/snappy/) | ||
### snappy.compressSync(input) | ||
The synchronous version of `snappy.compress`, returns the compressed value. | ||
### snappy.uncompress(compressed, [options,] callback) | ||
@@ -58,2 +62,6 @@ | ||
### snappy.uncompressSync(compressed, [options]) | ||
The synchronous version of `snappy.uncompress`, returns the uncompressed value. | ||
### snappy.isValidCompressed(input, callback) | ||
@@ -65,2 +73,6 @@ | ||
### snappy.isValidCompressedSync(input) | ||
The synchronous version of `snappy.isValidCompressed`, returns a boolean indicating if inpus was correctly compressed or not. | ||
### stream | ||
@@ -83,3 +95,3 @@ | ||
Copyright (c) 2011 - 2014 David Björklund & contributors | ||
Copyright (c) 2011 - 2015 David Björklund & contributors | ||
@@ -86,0 +98,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -1,25 +0,5 @@ | ||
/* | ||
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: | ||
var binding = require('bindings')('binding') | ||
var assert = require('assert') | ||
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 binding = require('bindings')('binding'); | ||
/** | ||
@@ -34,10 +14,18 @@ * Compress asyncronous. | ||
binding.compress(input, callback); | ||
}; | ||
binding.compress(input, callback) | ||
} | ||
exports.compressSync = function (input) { | ||
assert(typeof(input) === 'string' || Buffer.isBuffer(input), 'input must be a String or a Buffer') | ||
return binding.compressSync(input) | ||
} | ||
/** | ||
* Asyncronous decide if a buffer is compressed in a correct way. | ||
*/ | ||
exports.isValidCompressed = binding.isValidCompressed; | ||
exports.isValidCompressed = binding.isValidCompressed | ||
exports.isValidCompressedSync = binding.isValidCompressedSync; | ||
/** | ||
@@ -61,1 +49,11 @@ * Asyncronous uncompress previously compressed data. | ||
} | ||
exports.uncompressSync = function (compressed, opts) { | ||
assert(Buffer.isBuffer(compressed), 'input must be a Buffer'); | ||
opts = opts || {}; | ||
if (typeof(opts.asBuffer) !== 'boolean') | ||
opts.asBuffer = true | ||
return binding.uncompressSync(compressed, opts) | ||
} |
61
test.js
@@ -18,2 +18,9 @@ var test = require('tap').test | ||
test('compressSync() string', function (t) { | ||
var buffer = snappy.compressSync(inputString) | ||
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer') | ||
t.deepEqual(buffer, compressed, 'should compress to same as async version') | ||
t.end() | ||
}) | ||
test('compress() buffer', function (t) { | ||
@@ -28,6 +35,13 @@ snappy.compress(inputBuffer, function (err, buffer) { | ||
test('compressSync() buffer', function (t) { | ||
var buffer = snappy.compressSync(inputBuffer) | ||
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer') | ||
t.deepEqual(buffer, compressed, 'should compress to same as async version') | ||
t.end() | ||
}) | ||
test('isValidCompressed() on valid data', function (t) { | ||
snappy.isValidCompressed(compressed, function (err, isValidCompressed) { | ||
snappy.isValidCompressed(compressed, function (err, results) { | ||
t.error(err) | ||
t.equal(isValidCompressed, true) | ||
t.equal(results, true) | ||
t.end() | ||
@@ -38,5 +52,5 @@ }) | ||
test('isValidCompressed() on invalid data', function (t) { | ||
snappy.isValidCompressed(new Buffer('beep boop'), function (err, isValidCompressed) { | ||
snappy.isValidCompressed(new Buffer('beep boop'), function (err, results) { | ||
t.error(err) | ||
t.equal(isValidCompressed, false) | ||
t.equal(results, false) | ||
t.end() | ||
@@ -46,2 +60,14 @@ }) | ||
test('isValidCompressedSync() on valid data', function (t) { | ||
var results = snappy.isValidCompressedSync(compressed) | ||
t.equal(results, true) | ||
t.end() | ||
}) | ||
test('isValidCompressedSync() on invalid data', function (t) { | ||
var results = snappy.isValidCompressedSync(new Buffer('beep boop')) | ||
t.equal(results, false) | ||
t.end() | ||
}) | ||
test('uncompress() defaults to Buffer', function (t) { | ||
@@ -76,2 +102,27 @@ snappy.uncompress(compressed, function (err, buffer) { | ||
}) | ||
}) | ||
}) | ||
test('uncompressSync() defaults to Buffer', function (t) { | ||
var results = snappy.uncompressSync(compressed) | ||
t.deepEqual(results, inputBuffer) | ||
t.end() | ||
}) | ||
test('uncompressSync() returning a Buffer', function (t) { | ||
var results = snappy.uncompressSync(compressed, { asBuffer: true }) | ||
t.deepEqual(results, inputBuffer) | ||
t.end() | ||
}) | ||
test('uncompressSync() returning a String', function (t) { | ||
var results = snappy.uncompressSync(compressed, { asBuffer: false }) | ||
t.deepEqual(results, inputString) | ||
t.end() | ||
}) | ||
test('uncompressSync() on bad input', function (t) { | ||
t.throws(function () { | ||
snappy.uncompressSync(new Buffer('beep boop OMG OMG OMG')) | ||
}, 'Invalid input') | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1757479
56
148
111