()
| 88 | * exists so the portable engine can work against a real project at all. |
| 89 | */ |
| 90 | export function createNodeHostFs(): WasmHostFs { |
| 91 | return { |
| 92 | read(path) { |
| 93 | // Copied into a fresh Uint8Array: Buffer is a view onto a pooled allocation, |
| 94 | // and the Rust side reads the backing store directly. |
| 95 | const buffer = orNull(() => fs.readFileSync(path)); |
| 96 | return buffer === null ? null : new Uint8Array(buffer); |
| 97 | }, |
| 98 | |
| 99 | metadata(path) { |
| 100 | // Follows symlinks, matching std::fs::metadata. |
| 101 | const stats = orNull(() => fs.statSync(path)); |
| 102 | return stats === null ? null : toStat(stats); |
| 103 | }, |
| 104 | |
| 105 | symlinkMetadata(path) { |
| 106 | // Does not follow symlinks, matching std::fs::symlink_metadata. |
| 107 | const stats = orNull(() => fs.lstatSync(path)); |
| 108 | return stats === null ? null : toStat(stats); |
| 109 | }, |
| 110 | |
| 111 | readLink(path) { |
| 112 | return orNull(() => fs.readlinkSync(path, 'utf-8')); |
| 113 | }, |
| 114 | |
| 115 | canonicalize(path) { |
| 116 | return orNull(() => fs.realpathSync(path)); |
| 117 | }, |
| 118 | |
| 119 | readDir(path) { |
| 120 | const entries = orNull(() => fs.readdirSync(path, {withFileTypes: true})); |
| 121 | if (entries === null) { |
| 122 | return null; |
| 123 | } |
| 124 | return entries.map((entry) => ({ |
| 125 | name: entry.name, |
| 126 | // Dirent reflects the entry's own type without following symlinks, which is |
| 127 | // what the Rust walker needs to avoid descending into symlinked directories. |
| 128 | isFile: entry.isFile(), |
| 129 | isDir: entry.isDirectory(), |
| 130 | isSymlink: entry.isSymbolicLink(), |
| 131 | })); |
| 132 | }, |
| 133 | }; |
| 134 | } |
no outgoing calls
no test coverage detected