smartfile/dist/smartfile.remote.js

50 lines
3.0 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");
2017-02-18 16:01:52 +00:00
/* export let toFs = function (from: string, toPath: string) {
let done = plugins.q.defer()
let stream = plugins.smartrequest(from).pipe(plugins.fsExtra.createWriteStream(toPath))
stream.on('finish', function () {
done.resolve(toPath)
})
return done.promise
} */
2016-03-19 21:07:59 +00:00
/**
*
* @param fromArg
* @returns {any}
*/
exports.toObject = function (fromArg) {
2016-09-17 21:11:44 +00:00
let done = plugins.q.defer();
2017-02-18 16:01:52 +00:00
plugins.smartrequest.request(fromArg, {
method: 'get'
}).then((res) => {
if (res.statusCode === 200) {
done.resolve(res.body);
}
else {
console.log('could not get remote file from ' + fromArg);
2017-02-18 16:01:52 +00:00
done.reject(new Error('could not get remote file from ' + fromArg));
}
});
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();
2017-02-18 16:01:52 +00:00
plugins.smartrequest.get(fromArg).then((res) => {
if (res.statusCode === 200) {
done.resolve(res.body);
2016-03-19 21:07:59 +00:00
}
else {
2017-01-21 11:11:22 +00:00
console.error('could not get remote file from ' + fromArg);
2017-02-18 16:01:52 +00:00
done.reject(new Error('could not get remote file from ' + fromArg));
2016-03-19 21:07:59 +00:00
}
});
return done.promise;
2016-03-18 09:19:46 +00:00
};
2017-02-18 16:01:52 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBC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