smartfile/dist/smartfile.remote.js

69 lines
7.1 KiB
JavaScript
Raw Normal View History

2016-03-18 09:19:46 +00:00
"use strict";
require("typings-global");
var plugins = require("./smartfile.plugins");
var SmartfileInterpreter = require("./smartfile.interpreter");
var SmartfileGet = require("./smartfile.get");
2016-03-19 21:07:59 +00:00
exports.toFs = function (from, toPath) {
var done = plugins.q.defer();
2016-03-19 21:07:59 +00:00
var stream = plugins.request(from).pipe(plugins.fs.createWriteStream(toPath));
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) {
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(bodyString, SmartfileGet.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}
*/
exports.toString = function (fromArg) {
var 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);
}
;
});
return done.promise;
2016-03-18 09:19:46 +00:00
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0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