mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(pipe) add pipe-io from npm
This commit is contained in:
parent
275e96ffd2
commit
38fd38f582
9 changed files with 22 additions and 101 deletions
|
|
@ -17,9 +17,10 @@
|
|||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
|
||||
ponse = require(DIR_SERVER + 'ponse'),
|
||||
pipe = require(DIR_SERVER + 'pipe'),
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true}),
|
||||
|
||||
apiURL = CloudFunc.apiURL,
|
||||
|
||||
ConfigPath = DIR + 'json/config.json',
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
var fs = require('fs'),
|
||||
zlib = require('zlib'),
|
||||
|
||||
pipe = require('./pipe'),
|
||||
Util = require('../util'),
|
||||
|
||||
tryRequire = require('./tryRequire'),
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true}),
|
||||
|
||||
type = Util.type;
|
||||
|
||||
module.exports.read = function(files, options, callback) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
https = require('https'),
|
||||
qs = require('querystring'),
|
||||
pipe = require(DIR + 'pipe'),
|
||||
|
||||
tryRequire = require('./tryRequire'),
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true}),
|
||||
|
||||
Modules = require(DIR_JSON + 'modules'),
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
tar = tryRequire('tar'),
|
||||
fstream = tryRequire('fstream'),
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true}),
|
||||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
files = require(DIR + 'files'),
|
||||
pipe = require(DIR + 'pipe');
|
||||
files = require(DIR + 'files');
|
||||
|
||||
exports.pack = function(from, to, callback) {
|
||||
isDir(from, function(is) {
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
Util = require('../util');
|
||||
|
||||
module.exports = all;
|
||||
module.exports.getBody = getBody;
|
||||
|
||||
function on(event, emitter, callback) {
|
||||
var isSet,
|
||||
listeners = emitter.listeners(event),
|
||||
callbackStr = '' + callback;
|
||||
|
||||
isSet = listeners.some(function(func) {
|
||||
return '' + func === callbackStr;
|
||||
});
|
||||
|
||||
if (!isSet)
|
||||
emitter.on(event, callback);
|
||||
}
|
||||
|
||||
function all(streams, options, callback) {
|
||||
var n, write, isFSWrite;
|
||||
|
||||
Util.check(arguments, ['streams', 'callback']);
|
||||
|
||||
n = streams.length - 1;
|
||||
write = streams[n];
|
||||
isFSWrite = write instanceof fs.WriteStream;
|
||||
|
||||
Util.exec.if(!isFSWrite, function() {
|
||||
pipe(streams, options, callback);
|
||||
}, function(fn) {
|
||||
write.on('open', fn)
|
||||
.on('error', callback);
|
||||
});
|
||||
}
|
||||
|
||||
function pipe(streams, options, callback) {
|
||||
var main,
|
||||
read = streams[0];
|
||||
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
|
||||
options = {
|
||||
end: true
|
||||
};
|
||||
}
|
||||
|
||||
streams.forEach(function(stream) {
|
||||
on('error', stream, callback);
|
||||
|
||||
if (!main)
|
||||
main = stream;
|
||||
else
|
||||
main = main.pipe(stream, {
|
||||
end: options.end
|
||||
});
|
||||
});
|
||||
|
||||
on('end', read, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* get body of readStream
|
||||
*
|
||||
* @param readStream
|
||||
* @param callback
|
||||
*/
|
||||
function getBody(readStream, callback) {
|
||||
var sended, body = '';
|
||||
|
||||
Util.check(arguments, ['readStream', 'callback']);
|
||||
|
||||
readStream.on('data', function(chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
readStream.once('error', function(error) {
|
||||
sended = true;
|
||||
callback(error);
|
||||
});
|
||||
|
||||
readStream.once('end', function() {
|
||||
if (!sended)
|
||||
callback(null, body);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
@ -24,12 +24,12 @@
|
|||
github = require(DIR + 'github'),
|
||||
packer = require(DIR + 'packer'),
|
||||
ponse = require(DIR + 'ponse'),
|
||||
pipe = require(DIR + 'pipe'),
|
||||
|
||||
tryRequire = require('./tryRequire'),
|
||||
tryOptions = {log: true, exit: true},
|
||||
mellow = tryRequire('mellow', tryOptions),
|
||||
flop = tryRequire('flop', tryOptions),
|
||||
pipe = tryRequire('pipe-io', tryOptions),
|
||||
|
||||
isWin32 = process.platform === 'win32',
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@
|
|||
CloudFunc = require(DIR + 'cloudfunc'),
|
||||
Util = require(DIR + 'util'),
|
||||
|
||||
pipe = require(DIR_SERVER + 'pipe'),
|
||||
patch = require(DIR_SERVER + 'patch');
|
||||
patch = require(DIR_SERVER + 'patch'),
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true});
|
||||
|
||||
module.exports = function(name, readStream, callback) {
|
||||
var baseName = path.basename(name);
|
||||
|
|
|
|||
|
|
@ -10,8 +10,11 @@
|
|||
Util = require(DIR_LIB + 'util'),
|
||||
|
||||
tryRequire = require(DIR + 'tryRequire'),
|
||||
pipe = require(DIR + 'pipe'),
|
||||
mellow = tryRequire('mellow', {log: true, exit: true}),
|
||||
tryOptions = {log: true, exit: true},
|
||||
|
||||
mellow = tryRequire('mellow', tryOptions),
|
||||
pipe = tryRequire('pipe-io', tryOptions),
|
||||
|
||||
ponse = require(DIR + 'ponse'),
|
||||
|
||||
marked = tryRequire('marked');
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
"mellow": "~0.9.7",
|
||||
"minify": "~1.3.0",
|
||||
"nicki": "~1.2.0",
|
||||
"pipe-io": "~1.1.1",
|
||||
"socket.io": "~1.2.0",
|
||||
"tar": "~1.0.1"
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue