68 lines
6.8 KiB
JavaScript
68 lines
6.8 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
var plugins = require("./smartfile.plugins");
|
|
var SmartfileInterpreter = require("./smartfile.interpreter");
|
|
exports.toFs = function (from, toPath) {
|
|
var done = plugins.q.defer();
|
|
var stream = plugins.request(from).pipe(plugins.fs.createWriteStream(toPath));
|
|
stream.on('finish', function () {
|
|
done.resolve(toPath);
|
|
});
|
|
return done.promise;
|
|
};
|
|
/**
|
|
*
|
|
* @param filePathArg
|
|
* @returns {*}
|
|
*/
|
|
exports.toGulpStreamSync = function (filePathArg, baseArg) {
|
|
var stream = plugins.g.remoteSrc(filePathArg, {
|
|
base: baseArg
|
|
});
|
|
return stream;
|
|
};
|
|
/**
|
|
*
|
|
* @param fromArg
|
|
* @returns {any}
|
|
*/
|
|
exports.toObject = function (fromArg) {
|
|
var done = plugins.q.defer();
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
|
var returnObject;
|
|
if (!error && response.statusCode == 200) {
|
|
returnObject = SmartfileInterpreter.objectFile(bodyString, SmartfileInterpreter.filetype(fromArg));
|
|
done.resolve(returnObject);
|
|
}
|
|
else {
|
|
console.log('could not get remote file from ' + fromArg);
|
|
returnObject = undefined;
|
|
done.reject(returnObject);
|
|
}
|
|
;
|
|
});
|
|
return done.promise;
|
|
};
|
|
/**
|
|
*
|
|
* @param fromArg
|
|
* @returns {any}
|
|
*/
|
|
exports.toString = function (fromArg) {
|
|
var done = plugins.q.defer();
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
|
if (!error && response.statusCode == 200) {
|
|
done.resolve(bodyString);
|
|
}
|
|
else {
|
|
plugins.beautylog.error('could not get remote file from ' + fromArg);
|
|
bodyString = undefined;
|
|
done.reject(bodyString);
|
|
}
|
|
;
|
|
});
|
|
return done.promise;
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Zmls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