How to use the snappy.uncompressSync function in snappy

To help you get started, we’ve selected a few snappy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb-js / mongodb-core / test / mock / lib / server.js View on Github external
(message[index++] << 16) |
    (message[index++] << 24);

  // Unpack and decompress if the message is OP_COMPRESSED
  if (type === opcodes.OP_COMPRESSED) {
    const requestID = message.readInt32LE(4);
    const responseTo = message.readInt32LE(8);
    const originalOpcode = message.readInt32LE(16);
    const uncompressedSize = message.readInt32LE(20);
    const compressorID = message.readUInt8(24);

    const compressedData = message.slice(25);
    let uncompressedData;
    switch (compressorID) {
      case compressorIDs.snappy:
        uncompressedData = Snappy.uncompressSync(compressedData);
        break;
      case compressorIDs.zlib:
        uncompressedData = zlib.inflateSync(compressedData);
        break;
      default:
        uncompressedData = compressedData;
    }

    if (uncompressedData.length !== uncompressedSize) {
      throw new Error(
        'corrupt wire protocol message: uncompressed message is not the correct size'
      );
    }

    // Reconstruct the msgHeader of the uncompressed opcode
    const newMsgHeader = Buffer(MESSAGE_HEADER_SIZE);
github odota / core / js_parser / Parser.js View on Github external
function createStringTable(data) {
        //create a stringtable
        //console.error(data);
        //extract the native buffer from the string_data ByteBuffer, with the offset removed
        var buf = data.string_data.toBuffer();
        if (data.data_compressed) {
            //decompress the string data with snappy
            //early source 2 replays may use LZSS, we can detect this by reading the first four bytes of buffer
            buf = snappy.uncompressSync(buf);
        }
        //pass the buffer and parse string table data from it
        var items = parseStringTableData(buf, data.num_entries, data.user_data_fixed_size, data.user_data_size);
        //console.error(items);
        //remove the buf and replace with items, which is a decoded version of it
        data.string_data = {};
        // Insert the items into the table as an object
        items.forEach(function(it) {
            data.string_data[it.index] = it;
        });
        /*
        // Apply the updates to baseline state
	    if t.name == "instancebaseline" {
	    	p.updateInstanceBaseline()
	    }
        */
github odota / core / js_parser / parser-async.js View on Github external
//msgCompressed: = (command & dota.EDemoCommands_DEM_IsCompressed) == dota.EDemoCommands_DEM_IsCompressed
                var msgType = command & ~dota.EDemoCommands.DEM_IsCompressed;
                var msgCompressed = (command & dota.EDemoCommands.DEM_IsCompressed) === dota.EDemoCommands.DEM_IsCompressed;
                // Read the tick that the message corresponds with.
                //tick: = p.reader.readVarUint32()
                // This appears to actually be an int32, where a -1 means pre-game.
                /*
                if tick == 4294967295 {
                        tick = 0
                }
                */
                if (tick === 4294967295) {
                    tick = 0;
                }
                if (msgCompressed) {
                    buf = snappy.uncompressSync(buf);
                }
                var msg = {
                    tick: tick,
                    typeId: msgType,
                    size: size,
                    isCompressed: msgCompressed,
                    data: buf
                };
                return cb(null, msg);
            });
        });
github odota / core / js_parser / parser.js View on Github external
//msgCompressed: = (command & dota.EDemoCommands_DEM_IsCompressed) == dota.EDemoCommands_DEM_IsCompressed
            var msgType = command & ~dota.EDemoCommands.DEM_IsCompressed;
            var msgCompressed = (command & dota.EDemoCommands.DEM_IsCompressed) === dota.EDemoCommands.DEM_IsCompressed;
            // Read the tick that the message corresponds with.
            //tick: = p.reader.readVarUint32()
            // This appears to actually be an int32, where a -1 means pre-game.
            /*
            if tick == 4294967295 {
                    tick = 0
            }
            */
            if (tick === 4294967295) {
                tick = 0;
            }
            if (msgCompressed) {
                buf = snappy.uncompressSync(buf);
            }
            var msg = {
                tick: tick,
                typeId: msgType,
                size: size,
                isCompressed: msgCompressed,
                data: buf
            };
            return cb(err, msg);
        });
    });
github kesla / snappy.js / test / benchmark / bench.js View on Github external
var fs = require('fs')
  , path = require('path')

  , snappy = require('snappy')
  , snappyjs = require('../../snappy.js')

  , input = fs.readFileSync(path.resolve(__dirname, '../fixtures/urls.10K-compressed.bin'))

console.log('uncompress')
console.time('snappy')
for(var i = 0; i < 100; ++i)
  snappy.uncompressSync(input)
console.timeEnd('snappy')

console.time('snappy.js')
for(var i = 0; i < 100; ++i)
  snappyjs.uncompress(input)
console.timeEnd('snappy.js')

console.log('isValidCompressed')
console.time('snappy')
for(var i = 0; i < 100; ++i)
  snappy.isValidCompressedSync(input)
console.timeEnd('snappy')

console.time('snappy.js')
for(var i = 0; i < 100; ++i)
  snappyjs.isValidCompressed(input)
github zhipeng-jia / snappyjs / benchmark.js View on Github external
}).add('node-snappy#uncompress', function () {
    var i
    if (data.repeatedTimes) {
      for (i = 0; i < data.repeatedTimes; i++) {
        snappy.uncompressSync(data.compressedBuffer)
      }
    } else {
      snappy.uncompressSync(data.compressedBuffer)
    }
  }).add('snappyjs#uncompress', function () {
    var i
github polkadot-js / common / packages / db / src / FileFlatDb / Serialize.ts View on Github external
protected _deserializeValue (value: Buffer): Uint8Array | null {
    return bufferToU8a(
      this._isCompressed
        ? snappy.uncompressSync(value)
        : value
    );
  }
github polkadot-js / client / packages / client-db / src / engines / FileFlatDb / Serialize.ts View on Github external
protected _deserializeValue (value: Buffer): Uint8Array | null {
    return bufferToU8a(
      this._isCompressed
        ? snappy.uncompressSync(value)
        : value
    );
  }
github albertdb / Raft / router.js View on Github external
router.on('message',function(){
    var args = Array.apply(null, arguments);
    if(debug){
        var aux=args.slice();
        if(aux[3]=='c') aux[4]=snappy.uncompressSync(aux[4]);
        showArguments(aux);
    }
    router.send([args[2],'',args[0],args[3],args[4]]);
});
github albertdb / Raft / server.js View on Github external
socket.on('message',function(){
    var args = Array.apply(null, arguments);
    if(args[2]=='c') args[3]=snappy.uncompressSync(args[3]);
    if(debug) showArguments(args);
    var message=JSON.parse(args[3]);
    if(message.rpc=='appendEntries') appendEntries(message.term,message.leaderId,message.prevLogIndex,message.prevLogTerm,message.entries,message.leaderCommit);
    else if(message.rpc=='replyAppendEntries') replyAppendEntries(message.term,message.followerId,message.entriesToAppend,message.success);
    else if(message.rpc=='requestVote') requestVote(message.term,message.candidateId,message.lastLogIndex,message.lastLogTerm);
    else if(message.rpc=='replyVote') replyVote(message.term,message.voteGranted);
    else if(message.rpc=='installSnapshot') installSnapshot(message.term,message.leaderId,message.lastIncludedIndex,message.lastIncludedTerm,message.offset,message.data,message.done);
});

snappy

Fastest Snappy compression library in Node.js

MIT
Latest version published 1 year ago

Package Health Score

66 / 100
Full package analysis