Socket
Socket
Sign inDemoInstall

crc32-stream

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crc32-stream - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

8

CHANGELOG.md
## Changelog
**3.0.0** — <small>_April 29, 2019_</small> — [Diff](https://github.com/archiverjs/node-crc32-stream/compare/2.0.0...3.0.0)
- Require Node.js 6.9, update dependencies, use modern JS syntax (GH #10)
- Do not use the deprecated Buffer() constructor (GH #8)
- remove node v0.10 and v0.12 support
**2.0.0** — <small>_February 13, 2017_</small> — [Diff](https://github.com/archiverjs/node-crc32-stream/compare/1.0.1...2.0.0)

@@ -12,2 +18,2 @@

[Release Archive](https://github.com/archiverjs/node-crc32-stream/releases)
[Release Archive](https://github.com/archiverjs/node-crc32-stream/releases)

58

lib/crc32-stream.js

@@ -8,38 +8,42 @@ /**

*/
var inherits = require('util').inherits;
var Transform = require('readable-stream').Transform;
var crc32 = require('crc').crc32;
'use strict';
var CRC32Stream = module.exports = function CRC32Stream(options) {
Transform.call(this, options);
this.checksum = new Buffer(4);
this.checksum.writeInt32BE(0, 0);
const {Transform} = require('readable-stream');
this.rawSize = 0;
};
const {crc32} = require('crc');
inherits(CRC32Stream, Transform);
class CRC32Stream extends Transform {
constructor(options) {
super(options);
this.checksum = Buffer.allocUnsafe(4);
this.checksum.writeInt32BE(0, 0);
CRC32Stream.prototype._transform = function(chunk, encoding, callback) {
if (chunk) {
this.checksum = crc32(chunk, this.checksum);
this.rawSize += chunk.length;
this.rawSize = 0;
}
callback(null, chunk);
};
_transform(chunk, encoding, callback) {
if (chunk) {
this.checksum = crc32(chunk, this.checksum);
this.rawSize += chunk.length;
}
CRC32Stream.prototype.digest = function(encoding) {
var checksum = new Buffer(4);
checksum.writeUInt32BE(this.checksum >>> 0, 0);
return encoding ? checksum.toString(encoding) : checksum;
};
callback(null, chunk);
}
CRC32Stream.prototype.hex = function() {
return this.digest('hex').toUpperCase();
};
digest(encoding) {
const checksum = Buffer.allocUnsafe(4);
checksum.writeUInt32BE(this.checksum >>> 0, 0);
return encoding ? checksum.toString(encoding) : checksum;
}
CRC32Stream.prototype.size = function() {
return this.rawSize;
};
hex() {
return this.digest('hex').toUpperCase();
}
size() {
return this.rawSize;
}
}
module.exports = CRC32Stream;

@@ -8,63 +8,56 @@ /**

*/
var zlib = require('zlib');
var inherits = require('util').inherits;
var crc32 = require('crc').crc32;
'use strict';
var DeflateCRC32Stream = module.exports = function (options) {
zlib.DeflateRaw.call(this, options);
const {DeflateRaw} = require('zlib');
this.checksum = new Buffer(4);
this.checksum.writeInt32BE(0, 0);
const {crc32} = require('crc');
this.rawSize = 0;
this.compressedSize = 0;
class DeflateCRC32Stream extends DeflateRaw {
constructor(options) {
super(options);
// BC v0.8
if (typeof zlib.DeflateRaw.prototype.push !== 'function') {
this.on('data', function(chunk) {
if (chunk) {
this.compressedSize += chunk.length;
}
});
this.checksum = Buffer.allocUnsafe(4);
this.checksum.writeInt32BE(0, 0);
this.rawSize = 0;
this.compressedSize = 0;
}
};
inherits(DeflateCRC32Stream, zlib.DeflateRaw);
push(chunk, encoding) {
if (chunk) {
this.compressedSize += chunk.length;
}
DeflateCRC32Stream.prototype.push = function(chunk, encoding) {
if (chunk) {
this.compressedSize += chunk.length;
return super.push(chunk, encoding);
}
return zlib.DeflateRaw.prototype.push.call(this, chunk, encoding);
};
write(chunk, enc, cb) {
if (chunk) {
this.checksum = crc32(chunk, this.checksum);
this.rawSize += chunk.length;
}
DeflateCRC32Stream.prototype.write = function(chunk, enc, cb) {
if (chunk) {
this.checksum = crc32(chunk, this.checksum);
this.rawSize += chunk.length;
return super.write(chunk, enc, cb);
}
return zlib.DeflateRaw.prototype.write.call(this, chunk, enc, cb);
};
digest(encoding) {
const checksum = Buffer.allocUnsafe(4);
checksum.writeUInt32BE(this.checksum >>> 0, 0);
return encoding ? checksum.toString(encoding) : checksum;
}
DeflateCRC32Stream.prototype.digest = function(encoding) {
var checksum = new Buffer(4);
checksum.writeUInt32BE(this.checksum >>> 0, 0);
return encoding ? checksum.toString(encoding) : checksum;
};
hex() {
return this.digest('hex').toUpperCase();
}
DeflateCRC32Stream.prototype.hex = function() {
return this.digest('hex').toUpperCase();
};
size(compressed = false) {
if (compressed) {
return this.compressedSize;
} else {
return this.rawSize;
}
}
}
DeflateCRC32Stream.prototype.size = function(compressed) {
compressed = compressed || false;
if (compressed) {
return this.compressedSize;
} else {
return this.rawSize;
}
};
module.exports = DeflateCRC32Stream;

@@ -8,4 +8,8 @@ /**

*/
exports = module.exports = require('./crc32-stream');
exports.CRC32Stream = exports;
exports.DeflateCRC32Stream = require('./deflate-crc32-stream');
'use strict';
module.exports = {
CRC32Stream: require('./crc32-stream'),
DeflateCRC32Stream: require('./deflate-crc32-stream')
}
{
"name": "crc32-stream",
"version": "2.0.0",
"version": "3.0.0",
"description": "a streaming CRC32 checksumer",

@@ -23,3 +23,3 @@ "homepage": "https://github.com/archiverjs/node-crc32-stream",

"engines": {
"node": ">= 0.10.0"
"node": ">= 6.9.0"
},

@@ -31,7 +31,7 @@ "scripts": {

"crc": "^3.4.4",
"readable-stream": "^2.0.0"
"readable-stream": "^3.2.0"
},
"devDependencies": {
"chai": "^3.4.0",
"mocha": "^3.2.0"
"chai": "^4.0.0",
"mocha": "^6.0.2"
},

@@ -38,0 +38,0 @@ "keywords": [

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

# crc32-stream v2.0.0 [![Build Status](https://travis-ci.org/archiverjs/node-crc32-stream.svg?branch=master)](https://travis-ci.org/archiverjs/node-crc32-stream) [![Build status](https://ci.appveyor.com/api/projects/status/sy60s39cmyvd60i3/branch/master?svg=true)](https://ci.appveyor.com/project/ctalkington/node-crc32-stream/branch/master)
# CRC32 Stream [![Build Status](https://travis-ci.org/archiverjs/node-crc32-stream.svg?branch=master)](https://travis-ci.org/archiverjs/node-crc32-stream) [![Build status](https://ci.appveyor.com/api/projects/status/sy60s39cmyvd60i3/branch/master?svg=true)](https://ci.appveyor.com/project/ctalkington/node-crc32-stream/branch/master)
crc32-stream is a streaming CRC32 checksumer. It uses [buffer-crc32](https://www.npmjs.org/package/buffer-crc32) behind the scenes to reliably handle binary data and fancy character sets. Data is passed through untouched.
crc32-stream is a streaming CRC32 checksumer. It uses the [crc](https://www.npmjs.org/package/crc) module behind the scenes to reliably handle binary data and fancy character sets. Data is passed through untouched.

@@ -20,6 +20,6 @@ ### Install

```js
var CRC32Stream = require('crc32-stream');
const {CRC32Stream} = require('crc32-stream');
var source = fs.createReadStream('file.txt');
var checksum = new CRC32Stream();
const source = fs.createReadStream('file.txt');
const checksum = new CRC32Stream();

@@ -43,6 +43,6 @@ checksum.on('end', function(err) {

```js
var DeflateCRC32Stream = require('crc32-stream').DeflateCRC32Stream;
const {DeflateCRC32Stream} = require('crc32-stream');
var source = fs.createReadStream('file.txt');
var checksum = new DeflateCRC32Stream();
const source = fs.createReadStream('file.txt');
const checksum = new DeflateCRC32Stream();

@@ -81,2 +81,2 @@ checksum.on('end', function(err) {

- [Contributing](https://github.com/archiverjs/node-crc32-stream/blob/master/CONTRIBUTING.md)
- [MIT License](https://github.com/archiverjs/node-crc32-stream/blob/master/LICENSE-MIT)
- [MIT License](https://github.com/archiverjs/node-crc32-stream/blob/master/LICENSE-MIT)
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