feature(patch) add from npm

This commit is contained in:
coderaiser 2015-01-08 16:46:00 -05:00
parent d03196aa96
commit e5f4e48471
3 changed files with 2 additions and 56 deletions

View file

@ -9,7 +9,7 @@
Util = require(DIR_LIB + 'util'),
CloudFunc = require(DIR_LIB + 'cloudfunc'),
patch = require(DIR_SERVER + 'patch'),
patch = require('patchfile'),
ashify = require('ashify'),
mellow = require('mellow');

View file

@ -1,55 +0,0 @@
(function() {
'use strict';
var fs = require('fs'),
check = require('checkup'),
diff = require('daffy'),
flop = require('flop'),
exec = require('execon'),
ERROR_MSG = 'File is to big. ' +
'Could not patch files ' +
'bigger then ';
module.exports = function(name, patch, options, callback) {
check(arguments, ['name', 'patch', 'callback']);
if (!callback) {
callback = options;
options = {};
}
flop.read(name, 'size raw', function(error, size) {
if (!error)
if (isNaN(options.size) || size < options.size)
patchFile(name, patch, callback);
else
error = {
message: ERROR_MSG + options.size
};
if (error)
callback(error);
});
};
function patchFile(name, patch, callback) {
fs.readFile(name, 'utf8', function read(error, data) {
var diffResult;
if (error) {
callback(error);
} else {
error = exec.try(function() {
diffResult = diff.applyPatch(data, patch);
});
if (error)
callback(error);
else
fs.writeFile(name, diffResult, callback);
}
});
}
})();

View file

@ -43,6 +43,7 @@
"minify": "~1.4.0",
"minimist": "~1.1.0",
"mollify": "~1.0.0",
"patchfile": "~1.0.0",
"pipe-io": "~1.1.1",
"ponse": "~1.3.0",
"rendy": "~1.0.2",