smartfile/ts/smartfile.remote.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

import plugins = require('./smartfile.plugins');
import SmartfileInterpreter = require('./smartfile.interpreter');
2016-03-18 09:19:46 +00:00
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-18 09:19:46 +00:00
2016-03-19 21:07:59 +00:00
/**
*
* @param fromArg
* @returns {any}
*/
export let toObject = function(fromArg: string) {
let done = plugins.smartpromise.defer();
plugins.smartrequest
.request(fromArg, {
method: 'get'
})
.then((res: any) => {
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;
};
2016-03-18 09:19:46 +00:00
2016-03-19 21:07:59 +00:00
/**
*
* @param fromArg
* @returns {any}
*/
2016-09-20 15:56:49 +00:00
export let toString = (fromArg: string) => {
let done = plugins.smartpromise.defer();
2018-07-03 22:59:39 +00:00
plugins.smartrequest.getBinary(fromArg).then((res: any) => {
2017-02-18 16:01:52 +00:00
if (res.statusCode === 200) {
done.resolve(res.body);
2017-02-18 16:01:52 +00:00
} else {
done.reject(new Error('could not get remote file from ' + fromArg));
2017-02-18 16:01:52 +00:00
}
});
return done.promise;
};