From 3cc724c9bae94c2f79dd4a902782a66f688a1e61 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 22 Nov 2021 16:53:58 +0100 Subject: fix(runtime): support reading /proc using readFile (#12839) --- runtime/js/40_read_file.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'runtime/js/40_read_file.js') diff --git a/runtime/js/40_read_file.js b/runtime/js/40_read_file.js index 53ac9b08a..5e90b523a 100644 --- a/runtime/js/40_read_file.js +++ b/runtime/js/40_read_file.js @@ -4,13 +4,18 @@ ((window) => { const core = window.Deno.core; const { open, openSync } = window.__bootstrap.files; - const { readAllSyncSized, readAllInnerSized } = window.__bootstrap.io; + const { readAllSync, readAll, readAllSyncSized, readAllInnerSized } = + window.__bootstrap.io; function readFileSync(path) { const file = openSync(path); try { const { size } = file.statSync(); - return readAllSyncSized(file, size); + if (size === 0) { + return readAllSync(file); + } else { + return readAllSyncSized(file, size); + } } finally { file.close(); } @@ -20,7 +25,11 @@ const file = await open(path); try { const { size } = await file.stat(); - return await readAllInnerSized(file, size, options); + if (size === 0) { + return await readAll(file); + } else { + return await readAllInnerSized(file, size, options); + } } finally { file.close(); } -- cgit v1.2.3