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

stream-compare

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-compare - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

12

CHANGELOG.md
# Change Log
## [1.0.0](https://github.com/kevinoid/stream-compare/tree/1.0.0) (2017-02-24)
[Full Changelog](https://github.com/kevinoid/stream-compare/compare/v0.2.0...1.0.0)
## [v2.0.0](https://github.com/kevinoid/stream-compare/tree/v2.0.0) (2018-06-29)
[Full Changelog](https://github.com/kevinoid/stream-compare/compare/v1.0.0...v2.0.0)
- **BREAKING** Drop support for Node < 6.
- Drop unnecessary dependencies.
- Dependency version updates.
- Code style improvements.
## [v1.0.0](https://github.com/kevinoid/stream-compare/tree/v1.0.0) (2017-02-24)
[Full Changelog](https://github.com/kevinoid/stream-compare/compare/v0.2.0...v1.0.0)
- **No API Changes** Bump to 1.0 is declaration of stability rather than an

@@ -7,0 +15,0 @@ indication of changes.

142

index.js

@@ -8,7 +8,7 @@ /**

var EventEmitter = require('events').EventEmitter;
var Promise = require('any-promise');
var debug = require('debug')('stream-compare');
var extend = require('extend');
const {EventEmitter} = require('events');
const util = require('util');
const debug = util.debuglog('stream-compare');
/** Comparison type.

@@ -18,3 +18,3 @@ * @enum {string}

*/
var CompareType = {
const CompareType = {
/** A full (non-incremental) comparison. */

@@ -31,3 +31,3 @@ checkpoint: 'checkpoint',

*/
var ReadPolicy = {
const ReadPolicy = {
/** Reads are done concurrently using <code>'data'</code> events. */

@@ -51,3 +51,3 @@ flowing: 'flowing',

*/
var DEFAULT_OPTIONS = {
const DEFAULT_OPTIONS = {
abortOnError: false,

@@ -167,3 +167,3 @@ delay: 0,

function streamCompare(stream1, stream2, optionsOrCompare) {
var options;
let options;
if (optionsOrCompare) {

@@ -179,3 +179,3 @@ if (typeof optionsOrCompare === 'function') {

options = extend({}, DEFAULT_OPTIONS, options);
options = Object.assign({}, DEFAULT_OPTIONS, options);
if (!options.compare) {

@@ -193,5 +193,5 @@ options.compare = options.incremental;

}
if (options.readPolicy === 'least' &&
(typeof stream1.read !== 'function' ||
typeof stream2.read !== 'function')) {
if (options.readPolicy === 'least'
&& (typeof stream1.read !== 'function'
|| typeof stream2.read !== 'function')) {
throw new TypeError('streams must have .read() for readPolicy \'least\'');

@@ -202,11 +202,11 @@ }

}
if (!options.endEvents ||
typeof options.endEvents !== 'object' ||
options.endEvents.length !== Math.floor(options.endEvents.length)) {
if (!options.endEvents
|| typeof options.endEvents !== 'object'
|| options.endEvents.length !== Math.floor(options.endEvents.length)) {
throw new TypeError('options.endEvents must be Array-like');
}
options.endEvents = Array.prototype.slice.call(options.endEvents);
if (!options.events ||
typeof options.events !== 'object' ||
options.events.length !== Math.floor(options.events.length)) {
if (!options.events
|| typeof options.events !== 'object'
|| options.events.length !== Math.floor(options.events.length)) {
throw new TypeError('options.events must be Array-like');

@@ -222,20 +222,20 @@ }

if (!hasOwnProperty.call(ReadPolicy, options.readPolicy)) {
throw new RangeError('Invalid options.readPolicy \'' +
options.readPolicy + '\'');
throw new RangeError(`Invalid options.readPolicy '${
options.readPolicy}'`);
}
var reject;
var resolve;
var promise = new Promise(function(resolveArg, rejectArg) {
let reject;
let resolve;
const promise = new Promise(((resolveArg, rejectArg) => {
resolve = resolveArg;
reject = rejectArg;
});
var state1 = new StreamState();
var state2 = new StreamState();
var ended = 0;
var isDone = false;
var listeners1 = {};
var listeners2 = {};
var postEndImmediate;
var postEndTimeout;
}));
const state1 = new StreamState();
const state2 = new StreamState();
let ended = 0;
let isDone = false;
const listeners1 = {};
const listeners2 = {};
let postEndImmediate;
let postEndTimeout;

@@ -246,5 +246,5 @@ /** Gets the name of a stream for logging purposes.

function streamName(stream) {
return stream === stream1 ? 'stream1' :
stream === stream2 ? 'stream2' :
'unknown stream';
return stream === stream1 ? 'stream1'
: stream === stream2 ? 'stream2'
: 'unknown stream';
}

@@ -257,3 +257,3 @@

Object.keys(listeners1).forEach(function(eventName) {
Object.keys(listeners1).forEach((eventName) => {
stream1.removeListener(eventName, listeners1[eventName]);

@@ -264,7 +264,7 @@ });

stream1.removeListener('end', readNextOnEnd);
options.endEvents.forEach(function(eventName) {
options.endEvents.forEach((eventName) => {
stream1.removeListener(eventName, endListener1);
});
Object.keys(listeners2).forEach(function(eventName) {
Object.keys(listeners2).forEach((eventName) => {
stream2.removeListener(eventName, listeners2[eventName]);

@@ -275,3 +275,3 @@ });

stream2.removeListener('end', readNextOnEnd);
options.endEvents.forEach(function(eventName) {
options.endEvents.forEach((eventName) => {
stream2.removeListener(eventName, endListener2);

@@ -287,3 +287,3 @@ });

function onStreamError(err) {
debug(streamName(this) + ' emitted error', err);
debug(`${streamName(this)} emitted error`, err);
reject(err);

@@ -296,5 +296,5 @@ done();

var hasResultOrError = false;
let hasResultOrError = false;
try {
var result = compareFn(state1, state2);
const result = compareFn(state1, state2);
if (result !== undefined && result !== null) {

@@ -314,3 +314,3 @@ debug('Comparison produced a result:', result);

return true;
} else if (type === CompareType.last) {
} if (type === CompareType.last) {
resolve();

@@ -352,3 +352,3 @@ done();

// Note: Add event listeners before endListeners so end/error is recorded
options.events.forEach(function(eventName) {
options.events.forEach((eventName) => {
if (listeners1[eventName]) {

@@ -363,6 +363,6 @@ return;

function listener(/* event args */) {
function listener(...args) {
this.events.push({
name: eventName,
args: Array.prototype.slice.call(arguments)
args: Array.prototype.slice.call(args)
});

@@ -375,11 +375,11 @@

listeners1[eventName] = function listener1() {
debug('\'' + eventName + '\' event from stream1.');
listener.apply(state1, arguments);
listeners1[eventName] = function listener1(...args) {
debug(`'${eventName}' event from stream1.`);
listener.apply(state1, args);
};
stream1.on(eventName, listeners1[eventName]);
listeners2[eventName] = function listener2() {
debug('\'' + eventName + '\' event from stream2.');
listener.apply(state2, arguments);
listeners2[eventName] = function listener2(...args) {
debug(`'${eventName}' event from stream2.`);
listener.apply(state2, args);
};

@@ -404,3 +404,3 @@ stream2.on(eventName, listeners2[eventName]);

debug(streamName(this) + ' has ended.');
debug(`${streamName(this)} has ended.`);

@@ -414,8 +414,8 @@ if (options.incremental) {

if (ended === 2) {
var postEndCompare = function() {
const postEndCompare = function() {
doCompare(options.compare, CompareType.last);
};
if (options.delay) {
debug('All streams have ended. Delaying for ' + options.delay +
'ms before final compare.');
debug(`All streams have ended. Delaying for ${options.delay
}ms before final compare.`);
postEndTimeout = setTimeout(postEndCompare, options.delay);

@@ -436,3 +436,3 @@ } else {

}
options.endEvents.forEach(function(eventName) {
options.endEvents.forEach((eventName) => {
if (!options.abortOnError || eventName !== 'error') {

@@ -468,4 +468,4 @@ stream1.on(eventName, endListener1);

} else if (typeof data !== 'string' && !(data instanceof Buffer)) {
throw new TypeError('expected string or Buffer, got ' +
Object.prototype.toString.call(data) + '. Need objectMode?');
throw new TypeError(`expected string or Buffer, got ${
Object.prototype.toString.call(data)}. Need objectMode?`);
} else if (this.data === null || this.data === undefined) {

@@ -490,4 +490,4 @@ this.data = data;

this.data = Buffer.concat(
[this.data, data],
this.data.length + data.length
[this.data, data],
this.data.length + data.length
);

@@ -497,6 +497,6 @@ }

} else {
throw new TypeError('read returned ' +
Object.prototype.toString.call(data) + ', previously ' +
Object.prototype.toString.call(this.data) +
'. Need objectMode?');
throw new TypeError(`read returned ${
Object.prototype.toString.call(data)}, previously ${
Object.prototype.toString.call(this.data)
}. Need objectMode?`);
}

@@ -514,3 +514,3 @@ }

} catch (err) {
debug('Error adding data from ' + streamName(this), err);
debug(`Error adding data from ${streamName(this)}`, err);
reject(err);

@@ -530,7 +530,7 @@ done();

function readNext() {
var stream, state;
let stream, state;
while (!isDone) {
if (!state1.ended &&
(state2.ended || state1.totalDataLen <= state2.totalDataLen)) {
if (!state1.ended
&& (state2.ended || state1.totalDataLen <= state2.totalDataLen)) {
stream = stream1;

@@ -546,5 +546,5 @@ state = state1;

var data = stream.read();
const data = stream.read();
if (data === null) {
debug('Waiting for ' + streamName(stream) + ' to be readable...');
debug(`Waiting for ${streamName(stream)} to be readable...`);
stream.once('readable', readNext);

@@ -551,0 +551,0 @@ return;

@@ -22,12 +22,12 @@ /**

function incrementalProp(state1, state2, propName, compare) {
var values1 = state1[propName];
var values2 = state2[propName];
const values1 = state1[propName];
const values2 = state2[propName];
var result;
let result;
// Note: Values may be undefined if no data was read.
if (((values1 && values1.length !== 0) || state1.ended) &&
((values2 && values2.length !== 0) || state2.ended)) {
var minLen = Math.min(
values1 ? values1.length : 0,
values2 ? values2.length : 0
if (((values1 && values1.length !== 0) || state1.ended)
&& ((values2 && values2.length !== 0) || state2.ended)) {
const minLen = Math.min(
values1 ? values1.length : 0,
values2 ? values2.length : 0
);

@@ -78,11 +78,11 @@

return function incremental(state1, state2) {
var dataResult = compareData &&
incrementalProp(state1, state2, 'data', compareData);
var eventsResult = compareEvents &&
incrementalProp(state1, state2, 'events', compareEvents);
const dataResult = compareData
&& incrementalProp(state1, state2, 'data', compareData);
const eventsResult = compareEvents
&& incrementalProp(state1, state2, 'events', compareEvents);
return dataResult !== null && dataResult !== undefined ?
dataResult :
eventsResult;
return dataResult !== null && dataResult !== undefined
? dataResult
: eventsResult;
};
};
{
"name": "stream-compare",
"version": "1.0.0",
"version": "2.0.0",
"description": "Compare the behavior of readable streams.",

@@ -29,6 +29,6 @@ "keywords": [

"lint-doc": "jsdoc -t templates/silent -c jsdoc-lint.conf.json . && echo JSDoc passed.",
"lint-js": "node-version-gte-4 && eslint . && echo ESLint passed. || node-version-lt-4",
"lint-js": "eslint . && echo ESLint passed.",
"postpublish": "git -C doc push && git push --follow-tags origin master gh-pages && echo Remember to update GitHub Releases from CHANGELOG.md && echo until skywinder/github-changelog-generator#56 is fixed.",
"postversion": "rimraf doc && git clone -b gh-pages -l -q . doc && npm run doc && git -C doc add . && git -C doc commit -n -m \"Docs for v$npm_package_version\"",
"preversion": "depcheck --ignores bluebird,eslint-plugin-import --ignore-dirs doc && david && git-branch-is master && travis-status -b master -c -wx && appveyor-status -b master -c -w -p kevinoid/stream-compare && istanbul check-coverage --statements 95 coverage/coverage.json",
"preversion": "depcheck --ignores eslint-plugin-import,greenkeeper-lockfile --ignore-dirs doc && david -i eslint && git-branch-is master && travis-status -b master -c -wx && appveyor-status -b master -c -p kevinoid/stream-compare -w && istanbul check-coverage --statements 95 coverage/coverage.json",
"test": "npm run lint && npm run test-unit",

@@ -42,26 +42,25 @@ "test-cov": "npm run lint && npm run test-unit-cov",

},
"dependencies": {
"any-promise": "^1.1.0",
"debug": "^2.2.0",
"extend": "^3.0.0"
},
"dependencies": {},
"devDependencies": {
"bluebird": ">=2.0.0",
"buffer-equal": "^1.0.0",
"codecov": "^1.0.1",
"coveralls": "^2.11.6",
"eslint": "^3.0.0",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-import": "^2.2.0",
"codecov": "^3.0.0",
"coveralls": "^3.0.0",
"eslint": "^4.6.1",
"eslint-config-airbnb-base": "^13.0.0",
"eslint-plugin-import": "^2.7.0",
"greenkeeper-lockfile": "^1.15.1",
"istanbul": "^0.4.1",
"jsdoc": "^3.4.1",
"mocha": "^3.2.0",
"node-version-check": "^2.1.1",
"nodecat": "^1.0.0",
"mocha": "^5.0.0",
"nodecat": "^2.0.0",
"rimraf": "^2.2.0"
},
"engines": {
"node": ">=0.10",
"node": ">=6",
"npm": ">=1.3.7"
},
"greenkeeper": {
"ignore": [
"eslint"
]
}
}
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