Skip to content

Commit 3cc71c1

Browse files
committed
Add node:fs support
1 parent 61398ed commit 3cc71c1

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

lib/node.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,25 @@ extension type Process._(JSObject _) implements JSObject {
2626
/// Access to the node process object
2727
@JS()
2828
external Process get process;
29+
30+
/// Access to Node components
31+
abstract final class Node {
32+
/// Access to file system methods
33+
static NodeFs get fs => require('node:fs') as NodeFs;
34+
}
35+
36+
/// Node file system access
37+
extension type NodeFs._(JSObject _) implements JSObject {
38+
/// `path` string | Buffer | URL | integer filename or file descriptor
39+
/// `options` Object | string
40+
/// `encoding` string | null Default: null
41+
/// `flag` string See support of file system flags. Default: 'r'.
42+
/// Returns: string | Buffer
43+
///
44+
/// Returns the contents of the path.
45+
///
46+
/// If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
47+
///
48+
/// Ex to read a file as a string: `fs.readFileSync('/Users/joe/test.txt', 'utf8');`
49+
external JSAny readFileSync(JSAny path, JSAny options);
50+
}

0 commit comments

Comments
 (0)