diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-09-21 22:50:33 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-09-21 22:50:33 +0200 |
| commit | 10faab7941b28181c7647ff4e390ab651286bc32 (patch) | |
| tree | b0d71498d2a0649c7180940a38d2fbfa595ca515 /app/relay/runner.js | |
| parent | 53ddf1651d649f65d92e12d36c003ff623226e34 (diff) | |
| parent | 15d5cea9d1d94a6893ef1a55a916e68a182e5394 (diff) | |
merge
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([]) |
