smartfile/ts/smartfile.remote.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-09-20 15:56:49 +00:00
import 'typings-global'
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}
*/
2017-02-18 16:01:52 +00:00
export let toObject = function (fromArg: string) {
let done = plugins.q.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-09-20 15:56:49 +00:00
}
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) => {
2017-02-18 16:01:52 +00:00
let done = plugins.q.defer()
plugins.smartrequest.get(fromArg).then((res: any) => {
if (res.statusCode === 200) {
done.resolve(res.body)
} else {
console.error('could not get remote file from ' + fromArg)
done.reject(new Error('could not get remote file from ' + fromArg))
}
})
return done.promise
2016-09-20 15:56:49 +00:00
}