Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snappy

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snappy - npm Package Compare versions

Comparing version 4.1.2 to 5.0.0

.nyc_output/98278.json

12

package.json

@@ -5,3 +5,3 @@ {

"description": "Nodejs bindings to Google's Snappy compression library",
"version": "4.1.2",
"version": "5.0.0",
"homepage": "https://github.com/kesla/node-snappy",

@@ -14,3 +14,3 @@ "repository": {

"scripts": {
"test": "tap test.js",
"test": "nyc ava test.js && semistandard | snazzy",
"install": "./node_modules/.bin/node-gyp rebuild"

@@ -21,6 +21,10 @@ },

"nan": "2.2.0",
"node-gyp": "3.2.1"
"node-gyp": "3.3.1"
},
"devDependencies": {
"tap": "^5.1.1"
"ava": "^0.13.0",
"bluebird": "^3.3.4",
"nyc": "^6.1.1",
"semistandard": "^7.0.5",
"snazzy": "^3.0.0"
},

@@ -27,0 +31,0 @@ "gypfile": true,

@@ -0,5 +1,4 @@

var binding = require('bindings')('binding');
var assert = require('assert');
var binding = require('bindings')('binding')
var assert = require('assert')
/**

@@ -10,14 +9,15 @@ * Compress asyncronous.

*/
exports.compress = function(input, callback) {
if (!(typeof (input) === 'string' || Buffer.isBuffer(input)))
return callback(new Error('input must be a String or a Buffer'))
exports.compress = function (input, callback) {
if (!(typeof (input) === 'string' || Buffer.isBuffer(input))) {
return callback(new Error('input must be a String or a Buffer'));
}
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')
assert(typeof (input) === 'string' || Buffer.isBuffer(input), 'input must be a String or a Buffer');
return binding.compressSync(input)
}
return binding.compressSync(input);
};

@@ -27,3 +27,3 @@ /**

*/
exports.isValidCompressed = binding.isValidCompressed
exports.isValidCompressed = binding.isValidCompressed;

@@ -36,16 +36,13 @@ exports.isValidCompressedSync = binding.isValidCompressedSync;

*/
exports.uncompress = function(compressed, opts, callback) {
if (!Buffer.isBuffer(compressed))
return callback(new Error('input must be a Buffer'))
exports.uncompress = function (compressed, opts, callback) {
if (!callback) {
callback = opts
opts = {}
callback = opts;
}
if (typeof(opts.asBuffer) !== 'boolean')
opts.asBuffer = true
if (!Buffer.isBuffer(compressed)) {
return callback(new Error('input must be a Buffer'));
}
binding.uncompress(compressed, opts, callback)
}
binding.uncompress(compressed, uncompressOpts(opts), callback);
};

@@ -55,7 +52,7 @@ exports.uncompressSync = function (compressed, opts) {

opts = opts || {};
if (typeof(opts.asBuffer) !== 'boolean')
opts.asBuffer = true
return binding.uncompressSync(compressed, uncompressOpts(opts));
};
return binding.uncompressSync(compressed, opts)
function uncompressOpts (opts) {
return (opts && typeof opts.asBuffer === 'boolean') ? opts : {asBuffer: true};
}

@@ -1,123 +0,122 @@

var test = require('tap').test
'use strict';
, snappy = require('./snappy')
import test from 'ava';
import snappy from './snappy';
import Promise from 'bluebird';
, inputString = 'beep boop, hello world. OMG OMG OMG'
, inputBuffer = new Buffer(inputString)
, compressed
const inputString = 'beep boop, hello world. OMG OMG OMG';
const inputBuffer = new Buffer(inputString);
const compress = Promise.promisify(snappy.compress);
const isValidCompressed = Promise.promisify(snappy.isValidCompressed);
const uncompress = Promise.promisify(snappy.uncompress);
const {compressSync, isValidCompressedSync, uncompressSync} = snappy;
test('compress() string', function (t) {
snappy.compress(inputString, function (err, buffer) {
compressed = buffer
t.error(err)
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer')
t.end()
})
})
test('compress() string', function * (t) {
const buffer = yield compress(inputString);
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer');
});
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) {
const buffer = yield compress(inputBuffer);
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer');
});
test('compress() buffer', function (t) {
snappy.compress(inputBuffer, function (err, buffer) {
t.error(err)
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer')
t.deepEqual(buffer, compressed, 'should compress to same as string')
t.end()
})
})
test('compress() bad input', function * (t) {
t.throws(compress(123), 'input must be a String or a 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('compressSync() string', function * (t) {
const buffer = compressSync(inputString);
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer');
});
test('isValidCompressed() on valid data', function (t) {
snappy.isValidCompressed(compressed, function (err, results) {
t.error(err)
t.equal(results, true)
t.end()
})
})
test('compressSync() buffer', function * (t) {
const buffer = compressSync(inputBuffer);
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer');
});
test('isValidCompressed() on invalid data', function (t) {
snappy.isValidCompressed(new Buffer('beep boop'), function (err, results) {
t.error(err)
t.equal(results, false)
t.end()
})
})
test('isValidCompressed() on valid data', function * (t) {
const compressed = yield compress(inputBuffer);
const isCompressed = yield isValidCompressed(compressed);
t.ok(isCompressed);
});
test('isValidCompressedSync() on valid data', function (t) {
var results = snappy.isValidCompressedSync(compressed)
t.equal(results, true)
t.end()
})
test('isValidCompressed() on invalid data', function * (t) {
const isCompressed = yield isValidCompressed(new Buffer('beep boop'));
t.notOk(isCompressed);
});
test('isValidCompressedSync() on invalid data', function (t) {
var results = snappy.isValidCompressedSync(new Buffer('beep boop'))
t.equal(results, false)
t.end()
})
test('isValidCompressedSync() on valid data', function * (t) {
const compressed = yield compress(inputBuffer);
const isCompressed = isValidCompressedSync(compressed);
t.ok(isCompressed);
});
test('uncompress() defaults to Buffer', function (t) {
snappy.uncompress(compressed, function (err, buffer) {
t.error(err)
t.deepEqual(buffer, inputBuffer)
t.end()
})
})
test('isValidCompressedSync() on invalid data', function * (t) {
const isCompressed = isValidCompressedSync(new Buffer('beep boop'));
t.notOk(isCompressed);
});
test('uncompress() returning a Buffer', function (t) {
snappy.uncompress(compressed, { asBuffer: true }, function (err, buffer) {
t.error(err)
t.deepEqual(buffer, inputBuffer)
t.end()
})
})
test('uncompress() defaults to Buffer', function * (t) {
const compressed = yield compress(inputBuffer);
const buffer = yield uncompress(compressed);
t.same(buffer, inputBuffer);
});
test('uncompress() returning a String', function (t) {
snappy.uncompress(compressed, { asBuffer: false }, function (err, buffer) {
t.error(err)
t.deepEqual(buffer, inputString)
t.end()
})
})
test('uncompress() returning a Buffer', function * (t) {
const compressed = yield compress(inputBuffer);
const buffer = yield uncompress(compressed, { asBuffer: true });
t.same(buffer, inputBuffer);
});
test('uncompress() on bad input', function (t) {
snappy.uncompress(new Buffer('beep boop OMG OMG OMG'), function (err) {
t.equal(err.message, 'Invalid input')
t.end()
})
})
test('uncompress() returning a String', function * (t) {
const compressed = yield compress(inputBuffer);
const string = yield uncompress(compressed, { asBuffer: false });
t.same(string, inputString);
});
test('uncompressSync() defaults to Buffer', function (t) {
var results = snappy.uncompressSync(compressed)
t.deepEqual(results, inputBuffer)
t.end()
})
test('uncompress() does not change opts', function * (t) {
const compressed = yield compress(inputBuffer);
const opts = {};
yield uncompress(compressed, opts);
t.same(opts, {});
});
test('uncompressSync() returning a Buffer', function (t) {
var results = snappy.uncompressSync(compressed, { asBuffer: true })
t.deepEqual(results, inputBuffer)
t.end()
})
test('uncompress() on bad input', function * (t) {
t.throws(uncompress(new Buffer('beep boop OMG OMG OMG'), 'Invalid input'));
});
test('uncompressSync() returning a String', function (t) {
var results = snappy.uncompressSync(compressed, { asBuffer: false })
t.deepEqual(results, inputString)
t.end()
})
test('uncompress() on not a Buffer', function * (t) {
t.throws(uncompress('beep boop OMG OMG OMG', 'input must be a Buffer'));
});
test('uncompressSync() on bad input', function (t) {
test('uncompressSync() defaults to Buffer', function * (t) {
const compressed = yield compress(inputBuffer);
const buffer = uncompressSync(compressed);
t.same(buffer, inputBuffer);
});
test('uncompressSync() returning a Buffer', function * (t) {
const compressed = yield compress(inputBuffer);
const buffer = uncompressSync(compressed, { asBuffer: true });
t.same(buffer, inputBuffer);
});
test('uncompressSync() returning a String', function * (t) {
const compressed = yield compress(inputBuffer);
const string = uncompressSync(compressed, { asBuffer: false });
t.same(string, inputString);
});
test('uncompress() does not change opts', function * (t) {
const compressed = yield compress(inputBuffer);
const opts = {};
uncompressSync(compressed, opts);
t.same(opts, {});
});
test('uncompressSync() on bad input', function * (t) {
t.throws(function () {
snappy.uncompressSync(new Buffer('beep boop OMG OMG OMG'))
}, 'Invalid input')
t.end()
})
uncompressSync(new Buffer('beep boop OMG OMG OMG'));
}, 'Invalid input');
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc