Giter Club home page Giter Club logo

node-snappy-stream's Introduction

snappy-streambuild status

Compress data over a Stream using the snappy framing format

NPM

NPM

Installation

npm install snappy-stream

Benchmark

snappy is notably faster than gzip (as can be seen in benchmarks).

snappy-stream however is only slightly faster than gzip, because of the overhead of creating a Stream to begin with.

This is the result I'm seeing on my laptop (Macbook Air from 2012) running node benchmark (for now only testing compression)

  passthrough stream (no compression) x 644 ops/sec ±0.90% (84 runs sampled)
  zlib.createGzip() x 667 ops/sec ±0.50% (89 runs sampled)
  snappyStream.createCompressStream() x 690 ops/sec ±0.89% (86 runs sampled)

Example

Input

var snappyStream = require('snappy-stream')
  , compressStream = snappyStream.createCompressStream()
  , uncompressStream = snappyStream.createUncompressStream({
      asBuffer: false // optional option, asBuffer = false means that the stream emits strings, default: true
    })

compressStream.on('data', function (chunk) {
  console.log('Som data from the compressed stream', chunk)
  uncompressStream.write(chunk)
})

uncompressStream.on('data', function (chunk) {
  console.log('The data that was originally written')
  console.log(chunk)
})

compressStream.write('hello')
compressStream.write('world')
compressStream.end()

Output

Som data from the compressed stream <Buffer ff 06 00 00 73 4e 61 50 70 59>
Som data from the compressed stream <Buffer 01 09 00 00 bb 1f 82 a2 68 65 6c 6c 6f>
The data that was originally written
hello
Som data from the compressed stream <Buffer 01 09 00 00 2d 4e 1f a5 77 6f 72 6c 64>
The data that was originally written
world

Running tests

The tests are using the https://pypi.python.org/pypi/python-snappy library, so you need to install that first for it to work:

[sudo] pip install python-snappy

You also need to install the snappy library on your machine, using your favourite package manager (e.g. sudo apt-get install libsnappy-dev or brew install snappy).

Licence

Copyright (c) 2014 David Björklund

This software is released under the MIT license:

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.

node-snappy-stream's People

Contributors

hqidea avatar kesla avatar mpetrunic avatar pranaygp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-snappy-stream's Issues

Error in compression function : RangeError [ERR_OUT_OF_RANGE]

I am facing issue while compressing a data stream for large amount of data. Buffer checksum size is out of range.

Node version: 10.16.0
Npm version: 6.9.0
OS: Ubuntu 18.04

Below is the error:
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received 4675058066 at checkInt (internal/buffer.js:35:11) at writeUInt32LE (internal/buffer.js:509:3) at Buffer.writeUInt32LE (internal/buffer.js:522:10) at module.exports (/home/dhvani/IoT-Sense-m_v3.6.3/gdmtrunk/node_modules/snappy-stream/lib/checksum.js:9:14) at CompressStream._compressed (/home/dhvani/IoT-Sense-m_v3.6.3/gdmtrunk/node_modules/snappy-stream/lib/compress-stream.js:33:9) at /home/dhvani/IoT-Sense-m_v3.6.3/gdmtrunk/node_modules/snappy-stream/lib/compress-stream.js:60:12

uncompress doesn't work with multiple chunks

All the tests only consider single chunks. Uncompressing, however, fails when multiple chunks are piped through. This is because it expects the identifier to precede EVERY chunk, even though the specification only requires the very first chunk to be an identifier.

I'm adding a test case that makes this evident and will try to make a PR to fix it

Update Snappy Stream to latest version

Hi..can you please update snappystream to latest version? I get the security warning in one of our Nodejs App audit process. The snappystream module has already updated dependency for minimatch to latest.

Thanks

README Example - `undefined is not a function`

Running the following code:

$cat SnappyStreamExample.js
var snappyStream = require('stream')
    , compressStream = snappyStream.createCompressStream()
    , uncompressStream = snappyStream.createUncompressStream({
        asBuffer: false // optional option, asBuffer = false means that the stream emits strings, default: true
    })

    compressStream.on('data', function (chunk) {
        console.log('Som data from the compressed stream', chunk)
        uncompressStream.write(chunk)
    })

    uncompressStream.on('data', function (chunk) {
        console.log('The data that was originally written')
        console.log(chunk)
    })

    compressStream.write('hello')
    compressStream.write('world')
    compressStream.end()

I got the following error on line 2:

$node SnappyStreamExample.js
    , compressStream = snappyStream.createCompressStream()
                                    ^
TypeError: undefined is not a function

Perhaps I'm doing something wrong, or there's a problem in the README code?

Thanks

Question please?

I need to save a JSON object to a Redis Database.

I am able to save, but I can't decrypt back from Redis.

It seems like I need to add a Stream Identifier to the compressed string to indicate it's a Snappy type.

`
/**
* All streams should start with the "Stream identifier", containing chunk
* type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII.
*/
private static final byte[] STREAM_START = {
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59
};

`

This is the class the guys in Java are using..
https://programtalk.com/vs/?source=netty/codec/src/main/java/io/netty/handler/codec/compression/SnappyFrameEncoder.java

My question is, how can I generate a stream with those characteristics?

The rest of the payload it's a json object.

I.e.

const jsonObjectBody = '{ "myObjKey": "myObjValue" }';
const jsonObjectBodyStreamWithStreamIdentifier = ?????

Thank you very much!

Support M1 chips

A Lodestar user has reported issues building sse4_crc32 locally. Maybe a bump to the latest version of fast-crc32c 2.0.0 could fix the issue?

See ChainSafe/lodestar#2475 for more context

deprecated version of minimatc

I am not able to install snappy-steam due to below error. I believe if we only need to update this package dependencies to use latest snappy version (if that doesn't break the functionality).
`

[email protected] install /Users/faraz.zahabian/dev/playground/node_modules/snappy-stream/node_modules/fast-crc32c/node_modules/sse4_crc32
node-gyp rebuild
CXX(target) Release/obj.target/crc32c_sse42/src/crc32c_sse42.o
LIBTOOL-STATIC Release/crc32c_sse42.a
CXX(target) Release/obj.target/sse4_crc32/src/crc32c.o
SOLINK_MODULE(target) Release/sse4_crc32.node
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN cannot run in wd [email protected] node-gyp rebuild (wd=/Users/faraz.zahabian/dev/playground/node_modules/snappy-stream/node_modules/snappy)``
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.