mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(files) add from npm
This commit is contained in:
parent
8e94b38103
commit
4bb4b19cae
8 changed files with 20 additions and 147 deletions
|
|
@ -8,10 +8,13 @@
|
|||
Util = require(DIR_LIB + 'util'),
|
||||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
patch = require(DIR_SERVER + 'patch'),
|
||||
files = require(DIR_SERVER + 'files'),
|
||||
hash = require(DIR_SERVER + 'hash'),
|
||||
|
||||
tryRequire = require('./tryRequire'),
|
||||
mellow = tryRequire('mellow', {log: true, exit: true});
|
||||
tryOptions = {log: true, exit: true},
|
||||
|
||||
mellow = tryRequire('mellow', tryOptions),
|
||||
files = tryRequire('files-io', tryOptions);
|
||||
|
||||
module.exports = function(sock) {
|
||||
Util.check(arguments, ['socket']);
|
||||
|
|
|
|||
|
|
@ -1,135 +0,0 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
zlib = require('zlib'),
|
||||
|
||||
Util = require('../util'),
|
||||
|
||||
tryRequire = require('./tryRequire'),
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true}),
|
||||
|
||||
type = Util.type;
|
||||
|
||||
module.exports.read = function(files, options, callback) {
|
||||
var done = [],
|
||||
isDone = false,
|
||||
noOptions = type.function(options),
|
||||
readFiles = {},
|
||||
doneFunc = function (name, error, data) {
|
||||
done.pop();
|
||||
|
||||
if (error)
|
||||
done = [];
|
||||
else
|
||||
readFiles[name] = data;
|
||||
|
||||
if (!done.length && !isDone) {
|
||||
isDone = true;
|
||||
callback(error, readFiles);
|
||||
}
|
||||
};
|
||||
|
||||
Util.check(arguments, ['files', 'callback']);
|
||||
|
||||
if (noOptions) {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
done = files.map(function(name) {
|
||||
fs.readFile(name, options, doneFunc.bind(null, name));
|
||||
return name;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.readPipe = function readPipe(names, write, options, callback) {
|
||||
var name, lenght;
|
||||
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = {
|
||||
gzip : false
|
||||
};
|
||||
}
|
||||
|
||||
options.end = false;
|
||||
|
||||
if (names) {
|
||||
lenght = names.length;
|
||||
names = names.slice();
|
||||
}
|
||||
|
||||
if (!lenght) {
|
||||
write.end();
|
||||
callback();
|
||||
} else {
|
||||
name = names.shift();
|
||||
|
||||
pipeFiles(name, write, options, function(error) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
readPipe(names, write, options, callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* create pipe
|
||||
*
|
||||
* @param read - readable stream
|
||||
* @param write - writable stream
|
||||
*
|
||||
* @param options {
|
||||
* gzip
|
||||
* ungzip
|
||||
* notEnd
|
||||
* }
|
||||
*
|
||||
* @param callback - function(error) {}
|
||||
*/
|
||||
module.exports.pipe = pipeFiles;
|
||||
|
||||
function pipeFiles(read, write, options, callback) {
|
||||
var gzip,
|
||||
isStrRead = type.string(read),
|
||||
isStrWrite = type.string(write),
|
||||
isFunc = type.function(options),
|
||||
o = {},
|
||||
optionsRead = {
|
||||
bufferSize: 4 * 1024
|
||||
};
|
||||
|
||||
Util.check(arguments, ['read', 'write', 'callback']);
|
||||
|
||||
if (isFunc)
|
||||
callback = options;
|
||||
else
|
||||
o = options;
|
||||
|
||||
if (options.range)
|
||||
Util.extend(optionsRead, {
|
||||
start : o.range.start,
|
||||
end : o.range.end,
|
||||
});
|
||||
|
||||
if (isStrRead)
|
||||
read = fs.createReadStream(read, optionsRead);
|
||||
|
||||
if (isStrWrite)
|
||||
write = fs.createWriteStream(write);
|
||||
|
||||
if (o.gzip || o.gunzip) {
|
||||
if (o.gzip)
|
||||
gzip = zlib.createGzip();
|
||||
else
|
||||
gzip = zlib.createGunzip();
|
||||
|
||||
read = read.pipe(gzip);
|
||||
}
|
||||
|
||||
pipe([read, write], options, callback);
|
||||
}
|
||||
|
||||
})(this);
|
||||
|
|
@ -9,13 +9,15 @@
|
|||
zlib = require('zlib'),
|
||||
|
||||
tryRequire = require(DIR + 'tryRequire'),
|
||||
tryOptions = {log: true, exit: true},
|
||||
|
||||
tar = tryRequire('tar'),
|
||||
fstream = tryRequire('fstream'),
|
||||
pipe = tryRequire('pipe-io', {log: true, exit: true}),
|
||||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
files = require(DIR + 'files');
|
||||
pipe = tryRequire('pipe-io', tryOptions),
|
||||
files = tryRequire('files-io', tryOptions),
|
||||
|
||||
Util = require(DIR_LIB + 'util');
|
||||
|
||||
exports.pack = function(from, to, callback) {
|
||||
isDir(from, function(is) {
|
||||
|
|
|
|||
|
|
@ -7,15 +7,16 @@
|
|||
|
||||
Util = require(DIR + 'util'),
|
||||
|
||||
files = require(DIR_SERVER + 'files'),
|
||||
hash = require(DIR_SERVER + 'hash'),
|
||||
beautify = require(DIR_SERVER + 'beautify'),
|
||||
minify = require(DIR_SERVER + 'minify'),
|
||||
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
tryOptions = {log: true, exit: true},
|
||||
|
||||
mellow = tryRequire('mellow', tryOptions),
|
||||
flop = tryRequire('flop', tryOptions);
|
||||
flop = tryRequire('flop', tryOptions),
|
||||
files = tryRequire('files-io', tryOptions);
|
||||
|
||||
module.exports = function(query, name, callback) {
|
||||
var hashStream, error;
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@
|
|||
Util = require(DIR + 'util'),
|
||||
|
||||
packer = require(DIR_SERVER + 'packer'),
|
||||
files = require(DIR_SERVER + 'files'),
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
|
||||
tryRequire = require(DIR_SERVER + 'tryRequire'),
|
||||
tryOptions = {log: true, exit: true},
|
||||
flop = tryRequire('flop', tryOptions);
|
||||
|
||||
flop = tryRequire('flop', tryOptions),
|
||||
files = tryRequire('files-io', tryOptions);
|
||||
|
||||
module.exports = function(query, name, readStream, callback) {
|
||||
var baseName = path.basename(name),
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
mellow = tryRequire('mellow', tryOptions),
|
||||
ponse = tryRequire('ponse', tryOptions),
|
||||
files = tryRequire('files-io', tryOptions),
|
||||
|
||||
files = require(DIR_SERVER + 'files'),
|
||||
minify = require(DIR_SERVER + 'minify'),
|
||||
config = require(DIR_SERVER + 'config'),
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
"console-io": "~1.10.0",
|
||||
"dropbox": "0.10.x",
|
||||
"express": "~4.10.0",
|
||||
"files-io": "~1.2.0",
|
||||
"flop": "~1.0.25",
|
||||
"fstream": "~1.0.2",
|
||||
"http-auth": "2.1.x",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
Util = require(LIBDIR + 'util'),
|
||||
CloudFunc = require(LIBDIR + 'cloudfunc'),
|
||||
files = require(LIBDIR + 'server/files'),
|
||||
files = require('files-io'),
|
||||
|
||||
FS_DIR = HTMLDIR + 'fs/',
|
||||
EXPECT_PATH = DIR + 'test/lib/cloudfunc.html',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue