diff options
Diffstat (limited to 'app/relay/runner.js')
| -rw-r--r-- | app/relay/runner.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/relay/runner.js b/app/relay/runner.js index 44f2554..f1e3497 100644 --- a/app/relay/runner.js +++ b/app/relay/runner.js @@ -11,6 +11,7 @@ import readdir from 'fs-readdir-promise' import * as q from './queue' +const MAX_TRANSFER_SIZE = 1024 * 1024 * 2.5 const idle_state = { status: 'IDLE', task: {} } export const state = { @@ -169,6 +170,24 @@ export function module_dir(opt, dir){ return path.join(module.cwd, dir.replace(/\.\.?\//g, '')) } +export function read_file(opt, cb) { + const fn = module_dir(opt, opt.fn) + if (!fn) return cb([]) + stat_promise(fn).then(stat => { + if (stat.size > MAX_TRANSFER_SIZE) { + return cb({ error: 'file too large'}) + } + fs.readFile(fn, (err, buf) => cb({ + error: err, + name: opt.fn, + path: fn, + date: stat.ctime, + size: stat.size, + buf + })) + }).catch(() => cb({ error: 'error reading file' })) +} + export function list_directory(opt, cb) { const dir = module_dir(opt, opt.dir) if (!dir) return cb([]) |
