49 lines
2.8 KiB
JavaScript
49 lines
2.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./smartfile.plugins");
|
|
/* 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
|
|
} */
|
|
/**
|
|
*
|
|
* @param fromArg
|
|
* @returns {any}
|
|
*/
|
|
exports.toObject = function (fromArg) {
|
|
let done = plugins.smartpromise.defer();
|
|
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);
|
|
done.reject(new Error('could not get remote file from ' + fromArg));
|
|
}
|
|
});
|
|
return done.promise;
|
|
};
|
|
/**
|
|
*
|
|
* @param fromArg
|
|
* @returns {any}
|
|
*/
|
|
exports.toString = (fromArg) => {
|
|
let done = plugins.smartpromise.defer();
|
|
plugins.smartrequest.get(fromArg).then((res) => {
|
|
if (res.statusCode === 200) {
|
|
done.resolve(res.body);
|
|
}
|
|
else {
|
|
done.reject(new Error('could not get remote file from ' + fromArg));
|
|
}
|
|
});
|
|
return done.promise;
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwrQ0FBK0M7QUFHL0M7Ozs7Ozs7SUFPSTtBQUVKOzs7O0dBSUc7QUFDUSxRQUFBLFFBQVEsR0FBRyxVQUFVLE9BQWU7SUFDN0MsSUFBSSxJQUFJLEdBQU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