
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
diff-stream
Advanced tools
Compare the contents of two object streams, and produce a new stream consisting of the differences
Compare two ordered object streams and produce a new stream consisting of the differences.
var diffStream = require('diff-stream');
var fromArray = require('read-stream').array;
var stream1 = fromArray([{id: 1, name: 'albert'}, {id: 2, name: 'bob'}, {id: 3, name: 'cathy'}]);
var stream2 = fromArray([{id: 1, name: 'albert'}, {id: 2, name: 'joe'}, {id: 4, name: 'thomas'}, {id: 5, name: 'xavier'}]);
diffStream(stream1, stream2).pipe(process.stdout);
produces a stream of tuples:
[{id: 2, name: 'bob'}, {id: 2, name: 'joe'}]
[{id: 3, name: 'cathy'}, null]
[null, {id: 4, name: 'thomas'}]
[null, {id: 5, name: 'xavier'}]
This can be used, for example, to compare rows from streaming database queries, or long streams of JSON objects such as those produced by JSONStream, without having to actually buffer large amounts of data into memory.
Similar to the behavior of the ubiquitous diff command:
[obj1, obj2][obj1, null][null, obj2]Compare the readable streams stream1 and stream2, returning a new readable stream, which consists of tuple pairs.
The optional compare parameter may be a string key, used to determine the order of the objets. This defaults to id, which is a common key used to order objects in an object stream, such as results from a database query.
compare may also be a function, like the following:
diffStream(stream1, stream1, function(obj1, obj2) {
if (obj1.id < obj2.id)
this.left();
else if (obj1.id > obj2.id)
this.right();
else if (obj1.id == obj2.id && obj1.name == obj2.name)
this.equal();
else
this.notEqual();
}).pipe(process.stdout);
The function is called with pairs of objects from each stream. The function should call left, right, equal, or notEqual, to produce the corresponding output, and advance either stream1, or stream2, or both.
left will output [obj1, null], and advance stream1right will output [null, obj2], and advance stream2equal will output nothing, and advance both streamsnotEqual will output [obj1, obj2], and advance both streamsNote, it is important that the two object streams be ordered, and that this ordering matches the compare method as described above. If the streams consist of unordered objects, then pairs will not be aligned appropriately.
MIT
FAQs
Compare the contents of two object streams, and produce a new stream consisting of the differences
The npm package diff-stream receives a total of 4 weekly downloads. As such, diff-stream popularity was classified as not popular.
We found that diff-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.