@chainsafe/snappy-stream
Advanced tools
| var checksum = require("../lib/checksum"); | ||
| var fs = require("fs"); | ||
| var join = require("path").join; | ||
| var test = require("tap").test; | ||
| var bufferAlloc = require('buffer-alloc') | ||
| function bufferToArray(buffer) { | ||
| var array = new Array(buffer.length); | ||
| for (var i = 0; i < buffer.length; ++i) { | ||
| array[i] = buffer[i]; | ||
| } | ||
| return array; | ||
| } | ||
| if ("UPDATE_EXPECTED" in process.env) { | ||
| var expectedRows = []; | ||
| for (var i = 0; i < 1000; ++i) { | ||
| var buffer = bufferAlloc(1); | ||
| buffer[0] = i; | ||
| console.log(checksum(buffer)); | ||
| expectedRows.push(bufferToArray(checksum(buffer))); | ||
| } | ||
| fs.writeFileSync( | ||
| join(__dirname, "checksum.expected"), | ||
| JSON.stringify(expectedRows) | ||
| ); | ||
| } | ||
| var expectedRows = JSON.parse( | ||
| fs.readFileSync(join(__dirname, "checksum.expected")) | ||
| ); | ||
| test("Checksum", function (t) { | ||
| expectedRows.forEach(function (expected, index) { | ||
| var buffer = bufferAlloc(1); | ||
| buffer[0] = index; | ||
| var actual = bufferToArray(checksum(buffer)); | ||
| t.deepEqual(actual, expected, 'Buffer created from ' + index); | ||
| }); | ||
| t.end(); | ||
| }); |
Sorry, the diff of this file is not supported yet
+8
-0
| language: node_js | ||
| os: | ||
| - linux | ||
| node_js: | ||
| - 4 | ||
| - 6 | ||
| - 8 | ||
| - 10 | ||
| - 12 | ||
| - 14 | ||
| before_install: | ||
@@ -6,0 +14,0 @@ - sudo apt-get update -qq |
+4
-5
| var crc32c = require('fast-crc32c').calculate | ||
| var bufferAlloc = require('buffer-alloc') | ||
| module.exports = function (value) { | ||
| var x = crc32c(value) | ||
| , buffer = new Buffer(4) | ||
| var result = bufferAlloc(4) | ||
| // don't assert the size, since we're only interested in the parts that | ||
| // are within the UInt32LE-size | ||
| buffer.writeUInt32LE((((x >> 15) | (x << 17)) + 0xa282ead8), 0, true) | ||
| result.writeUInt32LE(((((x >> 15) | (x << 17)) + 0xa282ead8)) >>> 0, 0, true) | ||
| return buffer | ||
| return result | ||
| } |
@@ -5,10 +5,11 @@ var Transform = require('stream').Transform | ||
| , snappy = require('snappy') | ||
| , bufferFrom = require('buffer-from') | ||
| , checksum = require('./checksum') | ||
| , IDENTIFIER_FRAME = new Buffer([ | ||
| , IDENTIFIER_FRAME = bufferFrom([ | ||
| 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59 | ||
| ]) | ||
| , COMPRESSED = new Buffer([ 0x00 ]) | ||
| , UNCOMPRESSED = new Buffer([ 0x01 ]) | ||
| , COMPRESSED = bufferFrom([ 0x00 ]) | ||
| , UNCOMPRESSED = bufferFrom([ 0x01 ]) | ||
@@ -33,3 +34,3 @@ , CompressStream = function () { | ||
| COMPRESSED | ||
| , new Buffer([ size, size >> 8, size >> 16 ]) | ||
| , bufferFrom([ size, size >> 8, size >> 16 ]) | ||
| , checksum(chunk) | ||
@@ -47,3 +48,3 @@ , compressed | ||
| UNCOMPRESSED | ||
| , new Buffer([ size, size >> 8, size >> 16 ]) | ||
| , bufferFrom([ size, size >> 8, size >> 16 ]) | ||
| , checksum(chunk) | ||
@@ -50,0 +51,0 @@ , chunk |
@@ -6,6 +6,7 @@ | ||
| , bufferEqual = require('buffer-equal') | ||
| , bufferFrom = require('buffer-from') | ||
| , BufferList = require('bl') | ||
| , snappy = require('snappy') | ||
| , IDENTIFIER = new Buffer([ | ||
| , IDENTIFIER = bufferFrom([ | ||
| 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59 | ||
@@ -12,0 +13,0 @@ ]) |
+6
-4
| { | ||
| "name": "@chainsafe/snappy-stream", | ||
| "version": "3.0.1", | ||
| "version": "3.0.3", | ||
| "description": "Compress data over a Stream using the snappy framing format", | ||
@@ -21,6 +21,8 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "bl": "~4.0.2", | ||
| "bl": "^1.0.0", | ||
| "buffer-alloc": "^1.2.0", | ||
| "buffer-equal": "1.0.0", | ||
| "fast-crc32c": "^2.0.0", | ||
| "snappy": "~6.3.4" | ||
| "buffer-from": "^1.1.1", | ||
| "fast-crc32c": "^1.0.1", | ||
| "snappy": "^6.0.1" | ||
| }, | ||
@@ -27,0 +29,0 @@ "directories": { |
+37
-27
@@ -5,2 +5,4 @@ var spawn = require('child_process').spawn | ||
| , test = require('tap').test | ||
| , bufferFrom = require('buffer-from') | ||
| , largerInput = require('fs').readFileSync(__filename) | ||
@@ -41,3 +43,3 @@ , largerInputString = largerInput.toString() | ||
| uncompressStream.on('end', function () { | ||
| t.deepEqual(Buffer.concat(data), new Buffer('beep boop')) | ||
| t.deepEqual(Buffer.concat(data), bufferFrom('beep boop')) | ||
| t.end() | ||
@@ -48,3 +50,3 @@ }) | ||
| child.stdin.write(new Buffer('beep boop')) | ||
| child.stdin.write(bufferFrom('beep boop')) | ||
| child.stdin.end() | ||
@@ -105,3 +107,3 @@ }) | ||
| uncompressStream.write( | ||
| new Buffer([ 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x60 ]) | ||
| bufferFrom([ 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x60 ]) | ||
| ) | ||
@@ -120,3 +122,3 @@ uncompressStream.end() | ||
| uncompressStream.write( | ||
| new Buffer([ 0x0, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x60 ]) | ||
| bufferFrom([ 0x0, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x60 ]) | ||
| ) | ||
@@ -145,3 +147,3 @@ uncompressStream.end() | ||
| while (i < chunk.length) { | ||
| uncompressStream.write(new Buffer([ chunk[i] ])) | ||
| uncompressStream.write(bufferFrom([ chunk[i] ])) | ||
| i++ | ||
@@ -162,3 +164,3 @@ } | ||
| , data = [] | ||
| , IDENTIFIER = new Buffer([ | ||
| , IDENTIFIER = bufferFrom([ | ||
| 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59 | ||
@@ -173,3 +175,3 @@ ]) | ||
| uncompressStream.on('end', function () { | ||
| t.deepEqual(Buffer.concat(data), new Buffer('beep boop')) | ||
| t.deepEqual(Buffer.concat(data), bufferFrom('beep boop')) | ||
| t.end() | ||
@@ -181,5 +183,5 @@ }) | ||
| // "beep" | ||
| uncompressStream.write(new Buffer([0x01, 0x08, 0x00, 0x00, 0xfb, 0x5e, 0xc9, 0x6e, 0x62, 0x65, 0x65, 0x70])) | ||
| uncompressStream.write(bufferFrom([0x01, 0x08, 0x00, 0x00, 0xfb, 0x5e, 0xc9, 0x6e, 0x62, 0x65, 0x65, 0x70])) | ||
| // " boop" | ||
| uncompressStream.write(new Buffer([0x01, 0x09, 0x00, 0x00, 0x5f, 0xae, 0xb4, 0x84, 0x20, 0x62, 0x6f, 0x6f, 0x70])) | ||
| uncompressStream.write(bufferFrom([0x01, 0x09, 0x00, 0x00, 0x5f, 0xae, 0xb4, 0x84, 0x20, 0x62, 0x6f, 0x6f, 0x70])) | ||
| uncompressStream.end() | ||
@@ -190,4 +192,3 @@ }) | ||
| var child1 = spawn('python', [ '-m', 'snappy', '-c' ]) | ||
| , child2 = spawn('python', [ '-m', 'snappy', '-c' ]) | ||
| , IDENTIFIER = new Buffer([ | ||
| , IDENTIFIER = bufferFrom([ | ||
| 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59 | ||
@@ -212,5 +213,14 @@ ]) | ||
| }) | ||
| child2.stdout.on('data', function(chunk) { | ||
| uncompressStream.write(chunk.slice(10)) | ||
| uncompressStream.end() | ||
| child1.once('close', function () { | ||
| var child2 = spawn('python', [ '-m', 'snappy', '-c' ]) | ||
| child2.stdout.on('data', function(chunk) { | ||
| uncompressStream.write(chunk.slice(10)) | ||
| uncompressStream.end() | ||
| }) | ||
| // trigger second write after first write | ||
| child2.stdin.write(largerInput) | ||
| child2.stdin.end() | ||
| }) | ||
@@ -223,6 +233,2 @@ | ||
| child1.stdin.end() | ||
| // trigger second write after first write | ||
| child2.stdin.write(largerInput) | ||
| child2.stdin.end() | ||
| }) | ||
@@ -232,4 +238,3 @@ | ||
| var child1 = spawn('python', [ '-m', 'snappy', '-c' ]) | ||
| , child2 = spawn('python', [ '-m', 'snappy', '-c' ]) | ||
| , IDENTIFIER = new Buffer([ | ||
| , IDENTIFIER = bufferFrom([ | ||
| 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59 | ||
@@ -256,5 +261,14 @@ ]) | ||
| }) | ||
| child2.stdout.on('data', function(chunk) { | ||
| uncompressStream.write(chunk.slice(10)) | ||
| uncompressStream.end() | ||
| child1.on('close', () => { | ||
| var child2 = spawn('python', [ '-m', 'snappy', '-c' ]) | ||
| child2.stdout.on('data', function(chunk) { | ||
| uncompressStream.write(chunk.slice(10)) | ||
| uncompressStream.end() | ||
| }) | ||
| // trigger second write after first write | ||
| child2.stdin.write(largerInput) | ||
| child2.stdin.end() | ||
| }) | ||
@@ -267,6 +281,2 @@ | ||
| child1.stdin.end() | ||
| // trigger second write after first write | ||
| child2.stdin.write(largerInput) | ||
| child2.stdin.end() | ||
| }) |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
40394
80.92%18
12.5%514
9.13%6
50%7
40%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated