Closed Marak closed 9 years ago
Doesn't just comparing their buffers (file.contents
) work?
@kevva -
Yes, I believe that should work.
The gulp plugin I found is using fs
module and fs.stat
/ fs.readFile
. Trying to understand ecosystem a bit better. Is solution to update gulp-changed
to use vinyl object for comparison instead of fs
?
see: https://github.com/sindresorhus/gulp-changed/blob/master/index.js#L42
Do you have two vinyl objects already? In that case you could do:
function sha1(buf) {
return crypto.createHash('sha1').update(buf).digest('hex');
}
var src = sha1(srcFile.contents);
var dest = sha1(destFile.contents);
And then compare src
to dest
.
Thanks. I know this already.
The question is how to compare two sources of virtual files and ( more importantly ) to determine where this gets implemented in current gulp / vinyl ecosystem.
Should gulp-changed
be modified? Is new module required? Does this functionality already exist somewhere else?
@Marak I think the use case is different and warrants a new module. vinyl-diff sounds fine
10-4 @contra
I will update this issue if I get something working.
@contra -
I've created a new module vinyl-diff
The API currently looks like this:
var changed = require('../index').changed;
var vfs = require('vinyl-fs');
var map = require('map-stream');
var log = function (file, cb){
console.log(file)
cb(null, file);
};
vfs.src('./test/fixtures/new-files/**')
.pipe(map(log))
.pipe(changed(vfs.src('./test/fixtures/old-files/**'), { compare: "sha", dest: "old-files"})) // compares new files against old-files. only continues with changed files
.pipe(map(log));
I've tested it with fs and non-fs vinyl sources and it should be working.
Feedback would be appreciated. The current implementation has to pause the stream and wait for old-files to buffer. Is there a better way to do this?
@Marak Very cool, and this definitely solves the problem with doing partial builds across vinyl adapters. Nice work!
Closing since it isn't an issue, but more of a discussion. I added an issue to the gulpjs repo to add this to the docs for the 4.0 release
Are there currently any tools for comparing two sets of vinyl files and returning a diff between the two based on checksum?
I have found https://github.com/sindresorhus/gulp-changed/ , but this seems to be coupled directly to file-system and I seek to perform diff of vinyl files ( i.e. compare local files to remote files )
Any suggestions?