"use strict"; require("typings-global"); var plugins = require("./smartfile.plugins"); var SmartfileInterpreter = require("./smartfile.interpreter"); var SmartfileGet = require("./smartfile.get"); 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(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; }; /** * * @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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBQ2hELElBQU8sb0JBQW9CLFdBQVcseUJBQXlCLENBQUMsQ0FBQztBQUNqRSxJQUFPLFlBQVksV0FBVyxpQkFBaUIsQ0FBQyxDQUFDO0FBRXRDLFlBQUksR0FBRyxVQUFTLElBQVcsRUFBQyxNQUFhO0lBQ2hELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS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clxuICovXHJcbmV4cG9ydCBsZXQgdG9TdHJpbmcgPSAoZnJvbUFyZzpzdHJpbmcpID0+IHtcclxuICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XHJcbiAgICBwbHVnaW5zLnJlcXVlc3QuZ2V0KGZyb21BcmcsIGZ1bmN0aW9uIChlcnJvciwgcmVzcG9uc2UsIGJvZHlTdHJpbmcpIHtcclxuICAgICAgICBpZiAoIWVycm9yICYmIHJlc3BvbnNlLnN0YXR1c0NvZGUgPT0gMjAwKSB7XHJcbiAgICAgICAgICAgIGRvbmUucmVzb2x2ZShib2R5U3RyaW5nKTtcclxuICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy5lcnJvcignY291bGQgbm90IGdldCByZW1vdGUgZmlsZSBmcm9tICcgKyBmcm9tQXJnKTtcclxuICAgICAgICAgICAgYm9keVN0cmluZyA9IHVuZGVmaW5lZDtcclxuICAgICAgICAgICAgZG9uZS5yZWplY3QoYm9keVN0cmluZyk7XHJcbiAgICAgICAgfTtcclxuICAgIH0pO1xyXG4gICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcclxufTtcclxuXHJcbiJdfQ==