"use strict"; require("typings-global"); const plugins = require("./smartfile.plugins"); const SmartfileInterpreter = require("./smartfile.interpreter"); exports.toFs = function (from, toPath) { let done = plugins.q.defer(); let stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath)); stream.on('finish', function () { done.resolve(toPath); }); return done.promise; }; /** * * @param fromArg * @returns {any} */ exports.toObject = function (fromArg) { let done = plugins.q.defer(); plugins.request.get(fromArg, function (error, response, bodyString) { let 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 = (fromArg) => { let done = plugins.q.defer(); plugins.request.get(fromArg, function (error, response, bodyString) { if (!error && response.statusCode === 200) { done.resolve(bodyString); } else { console.error('could not get remote file from ' + fromArg); bodyString = undefined; done.reject(bodyString); } }); return done.promise; }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M7QUFDL0MsZ0VBQWdFO0FBRXJELFFBQUEsSUFBSSxHQUFHLFVBQVMsSUFBWSxFQUFDLE1BQWM7SUFDbEQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLGlCQUFpQixDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUE7S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