Skip to content

Commit 99c94eb

Browse files
committed
vfs: address code review feedback
- Revert unintended whitespace change in lib/fs.js - Use JSON.stringify() in documentation examples for consistency - Add comment in streams.js explaining #openFile error handling - Document path encoding behavior in overlay mode
1 parent 5c5868f commit 99c94eb

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

doc/api/vfs.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,17 @@ including `string`, `Buffer`, `TypedArray`, and `DataView` where applicable.
390390
#### Overlay mode behavior
391391

392392
When overlay mode is enabled, the following behavior applies to `fs` operations
393-
on mounted paths:
393+
on mounted paths.
394+
395+
**Path encoding:** The VFS uses UTF-8 encoding for file and directory names
396+
internally. In overlay mode, path matching is performed using the VFS's UTF-8
397+
encoding. When falling through to the real file system, paths are passed to
398+
the native file system APIs which handle encoding according to platform
399+
conventions (UTF-8 on most Unix systems, UTF-16 on Windows). This means the
400+
VFS inherits the underlying file system's encoding behavior for paths that
401+
fall through, while VFS-internal paths always use UTF-8.
402+
403+
**Operation routing:**
394404

395405
* **Read operations** (`readFile`, `readdir`, `stat`, `lstat`, `access`,
396406
`exists`, `realpath`, `readlink`): Check VFS first. If the path doesn't exist
@@ -768,7 +778,7 @@ const vfs = require('node:vfs');
768778

769779
const myVfs = vfs.create();
770780
myVfs.mkdirSync('/data');
771-
myVfs.writeFileSync('/data/config.json', '{}');
781+
myVfs.writeFileSync('/data/config.json', JSON.stringify({}));
772782

773783
// This works - symlink within VFS
774784
myVfs.symlinkSync('/data/config.json', '/config');
@@ -797,7 +807,7 @@ const fs = require('node:fs');
797807

798808
const myVfs = vfs.create({ overlay: true });
799809
myVfs.mkdirSync('/data');
800-
myVfs.writeFileSync('/data/config.json', '{"source": "vfs"}');
810+
myVfs.writeFileSync('/data/config.json', JSON.stringify({ source: 'vfs' }));
801811
myVfs.symlinkSync('/data/config.json', '/data/link');
802812
myVfs.mount('/app');
803813

lib/fs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,6 +3207,7 @@ function globSync(pattern, options) {
32073207
return new Glob(pattern, options).globSync();
32083208
}
32093209

3210+
32103211
module.exports = fs = {
32113212
appendFile,
32123213
appendFileSync,

lib/internal/vfs/streams.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class VirtualReadStream extends Readable {
4848
this.#pos = start;
4949
this.#autoClose = options.autoClose !== false;
5050

51-
// Open the file on next tick so listeners can be attached
51+
// Open the file on next tick so listeners can be attached.
52+
// Note: #openFile will not throw - if it fails, the stream is destroyed.
5253
process.nextTick(() => this.#openFile());
5354
}
5455

0 commit comments

Comments
 (0)