Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Allow file descriptor arguments to fs/readFile #462

Closed
dbohdan opened this issue Mar 4, 2019 · 0 comments
Closed

Allow file descriptor arguments to fs/readFile #462

dbohdan opened this issue Mar 4, 2019 · 0 comments

Comments

@dbohdan
Copy link

dbohdan commented Mar 4, 2019

Currently fs/readFile expects the path argument to be a string.

> cat test.cljs
(require '["fs"])

(fs/readFile 0
             "utf8"
             (fn [err data] (js/console.log data)))

> lumo test.cljs < test.cljs
The "path" argument must be of type string. Received type number
         assertPath (path.cljs:39:11)
         Object.resolve (path.cljs:168:7)
         getKey (C:NaN:37)
         readFile (C:NaN:172)
         Object.<anonymous> (C:NaN:3)
         Module._compile (internal/modules/cjs/loader.cljs:689:30)
         (Object.It)
         (Object.lumo.repl.caching_node_eval)
         (NO_SOURCE_FILE <embedded>:6265:9)
         z (NO_SOURCE_FILE <embedded>:6266:22)

However, per the official Node.js documentation path may be an integer representing a file descriptor. This is convenient, e.g., for reading the whole of the standard input.

> cat test.js
const fs = require('fs');

fs.readFile(0, 'utf8', (err, data) => console.log(data));

> node test.js < test.js
const fs = require('fs');

fs.readFile(0, 'utf8', (err, data) => console.log(data));

The workaround of "/dev/stdin" does not work on Windows.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant