From c10277480a6c993740840e1715d9ad451b184acf Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 14 Mar 2014 11:00:47 -0400 Subject: [PATCH] feature(files) rm dir --- lib/server.js | 35 +++++++++++++++++++++-------------- lib/server/files.js | 2 +- lib/server/fstream.js | 38 ++++++++++++++++++++++++++++++++++++++ lib/server/join.js | 9 +++------ 4 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 lib/server/fstream.js diff --git a/lib/server.js b/lib/server.js index 50b4f02d..9b977dda 100644 --- a/lib/server.js +++ b/lib/server.js @@ -34,18 +34,20 @@ express = main.express, expressApp, files = main.files, + emptyHandler = function(req, res, next) { Util.exec(next) }, + Server, Rest, Route; - join = join && Util.bind(join, beforeJoin, DIR) || Util.exec.bind(Util); + join = join && Util.bind(join, beforeJoin) || emptyHandler; /* базовая инициализация */ function init(pAppCachProcessing) { var config = main.config; /* создаём файл app cache */ - if (config.appcache && AppCache && config.server ) - Util.exec( pAppCachProcessing ); + if (config.appcache && AppCache && config.server) + Util.exec( pAppCachProcessing); } @@ -242,32 +244,37 @@ } function beforeJoin(names, callback) { - var i, name, check, minName, dir, + var i, name, check, minName, + func, funcs = [], + dir = DIR, config = main.config, n = names.length; - if (!config.minify) - Util.exec(callback); - else { - for (i = 0; i < n; i++) { - name = Path.join(DIR, names[i]); + for (i = 0; i < n; i++) { + name = Path.join(dir, names[i]); + names[i] = name; + + if (config.minify) { check = checkExtension(name); if (check) { minName = Minify.getName(name); if (name !== minName) { - names[i] = minName; - dir = ''; + names[i] = minName; } } - + funcs.push(Util.bind(minify, name)); } - - Util.asyncCall(funcs, callback); } + + func = Util.exec(callback, names); + + Util.ifExec(!config.minify, func, function(callback) { + Util.asyncCall(funcs, callback); + }); } function checkExtension(name) { diff --git a/lib/server/files.js b/lib/server/files.js index b6eb089b..16c6b137 100644 --- a/lib/server/files.js +++ b/lib/server/files.js @@ -63,7 +63,7 @@ p.write.end(); Util.exec(p.callback); } else { - name = p.dir + names.shift(); + name = names.shift(); pipe.create({ from : name, diff --git a/lib/server/fstream.js b/lib/server/fstream.js new file mode 100644 index 00000000..5b47744f --- /dev/null +++ b/lib/server/fstream.js @@ -0,0 +1,38 @@ +(function () { + 'use strict'; + + if (!global.cloudcmd) + return console.log( + '# fstream.js' + '\n' + + '# -----------' + '\n' + + '# Module is part of Cloud Commander,' + '\n' + + '# used for work with files.' + '\n' + + '# http://cloudcmd.io' + '\n'); + + var main = global.cloudcmd.main, + fs = main.fs, + Util = main.util, + fstream = main.require('fstream'), + tar = main.require('tar'); + + + exports.pack = packDir; + + function packDir(path, stream) { + var dirStream, tarStream, ret; + + if (tar && fstream) { + dirStream = fstream.Reader({ + type: "Directory", + path: path + }); + + tarStream = tar.Pack({}); + + ret = dirStream.pipe(tarStream); + } + + return ret; + } + +})(); diff --git a/lib/server/join.js b/lib/server/join.js index dcafeac0..e1de458c 100644 --- a/lib/server/join.js +++ b/lib/server/join.js @@ -9,9 +9,9 @@ module.exports = join; - function join(before, dir, req, res, callback) { + function join(before, req, res, callback) { var names, - readFunc = Util.bind(readPipe, req, res, dir), + readFunc = Util.bind(readPipe, req, res), path = main.getPathName(req), isJoin = CloudFunc.isJoinURL(path); @@ -20,8 +20,6 @@ else { names = CloudFunc.getJoinArray(path); - readFunc = Util.bind(readFunc, names); - Util.ifExec(!before, readFunc, function(callback) { before(names, callback); }); @@ -30,7 +28,7 @@ return isJoin; } - function readPipe(req, res, dir, names) { + function readPipe(req, res, names) { var stream, path = main.getPathName(req), gzip = zlib.createGzip(), @@ -48,7 +46,6 @@ files.readPipe({ names : names, - dir : dir, write : stream, callback : function(error) { var errorStr;