smartfile/dist/smartfile.remote.js

66 lines
4.4 KiB
JavaScript
Raw Normal View History

2016-03-18 09:19:46 +00:00
"use strict";
require("typings-global");
2016-07-17 15:34:15 +00:00
const plugins = require("./smartfile.plugins");
const SmartfileInterpreter = require("./smartfile.interpreter");
2016-03-19 21:07:59 +00:00
exports.toFs = function (from, toPath) {
2016-09-17 21:11:44 +00:00
var done = plugins.q.defer();
2016-07-19 18:28:28 +00:00
var stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
2016-03-19 21:07:59 +00:00
stream.on('finish', function () {
done.resolve(toPath);
2016-03-18 09:19:46 +00:00
});
return done.promise;
2016-03-18 09:19:46 +00:00
};
2016-03-19 21:07:59 +00:00
/**
*
* @param filePathArg
* @returns {*}
*/
exports.toGulpStreamSync = function (filePathArg, baseArg) {
2016-07-17 15:34:15 +00:00
let stream = plugins.g.remoteSrc(filePathArg, {
2016-03-19 21:07:59 +00:00
base: baseArg
});
return stream;
};
/**
*
* @param fromArg
* @returns {any}
*/
exports.toObject = function (fromArg) {
2016-09-17 21:11:44 +00:00
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
2016-07-17 15:34:15 +00:00
let returnObject;
if (!error && response.statusCode == 200) {
2016-06-23 16:31:55 +00:00
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;
};
2016-03-19 21:07:59 +00:00
/**
*
* @param fromArg
* @returns {any}
*/
2016-07-17 15:34:15 +00:00
exports.toString = (fromArg) => {
2016-09-17 21:11:44 +00:00
let done = plugins.q.defer();
2016-03-19 21:07:59 +00:00
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);
2016-03-19 21:07:59 +00:00
bodyString = undefined;
done.reject(bodyString);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