Merge two files like git
npm install safe-merge-files
Content of oldFile
and newFile
will be merged and written into newFile
.
If conflict occurs, it will create git like merge conflict result which should be resolved manually. To resolve conflict automatically, use force
option.
oldFile
<string> Old filenamenewFile
<string> New filenameoptions
<object>callback
<Function>
Content of oldFile
and newFile
will be merged and written into newFile
.
If conflict occurs, it will create git like merge conflict result which should be resolved manually. To resolve conflict automatically, use force
option.
oldFile
<string> | <ReadStream> Old filename or a Readable StreamnewFile
<string> | <ReadStream> New filename or a Readable Streamoptions
<object>outputFile
<string> Defaults tonull
. If specified, the merged output will be written inoutputFile
instead ofnewFile
force
<boolean> Defaults tofalse
. If set totrue
, conflicts will be resolved by prefering new changes.stream
<boolean> Defaults tofalse
. If set to true, it returns a Readable Stream that can be consumed or piped.- Returns: <ReadStream> | <Integer>
If
options.stream
isfalse
, any of [0 = no change, 1 = no conflict, -1 = conflict] is returned.
var safeMergeFiles = require('safe-merge-files');
safeMergeFiles('before-change.txt', 'after-change.txt',function(err,change){
if(change==0) console.log('No change');
else if(change==1) console.log('Modified');
else console.log('Conflict - please resolve it mannually');
})
var safeMergeFiles = require('safe-merge-files');
safeMergeFiles('before-change.txt', 'after-change.txt',{
force: true
},function(err,change){
if(change==0) console.log('No change');
else if(change==1) console.log('Modified');
else console.log('Conflict - resolved');
})
var safeMergeFiles = require('safe-merge-files');
var stream= safeMergeFiles.Sync(fs.createReadStream("old_file"), fs.createReadStream("new_file"), {
stream:true
});
var output=fs.createWriteStream("output_file");
stream.pipe(output);
npm test