2018-07-03 06:55:09 +00:00
|
|
|
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}
|
|
|
|
*/
|
2018-07-03 06:55:09 +00:00
|
|
|
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) => {
|
2018-07-03 06:55:09 +00:00
|
|
|
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) {
|
2018-07-03 06:55:09 +00:00
|
|
|
done.resolve(res.body);
|
2017-02-18 16:01:52 +00:00
|
|
|
} else {
|
2018-07-03 06:55:09 +00:00
|
|
|
done.reject(new Error('could not get remote file from ' + fromArg));
|
2017-02-18 16:01:52 +00:00
|
|
|
}
|
2018-07-03 06:55:09 +00:00
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|