smartfile/dist/smartfile.remote.js

51 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-03-18 09:19:46 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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) {
let done = plugins.smartpromise.defer();
2018-07-03 22:59:39 +00:00
plugins.smartrequest
.request(fromArg, {
2017-02-18 16:01:52 +00:00
method: 'get'
2018-07-03 22:59:39 +00:00
})
.then((res) => {
2017-02-18 16:01:52 +00:00
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) => {
let done = plugins.smartpromise.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-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
};
2018-07-03 22:59:39 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Q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