diff options
Diffstat (limited to 'runtime/js/40_read_file.js')
-rw-r--r-- | runtime/js/40_read_file.js | 15 |
1 files changed, 12 insertions, 3 deletions
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(); } |