memoryProvider.setReadOnly()


将提供程序锁定为只读模式。之后通过任何使用此提供程序的 VirtualFileSystem 进行写入都会抛出 EROFS。无法将提供程序恢复为可写模式。

🌐 Locks the provider into read-only mode. Subsequent writes through any VirtualFileSystem using this provider throw EROFS. There is no way to revert the provider to writable.

const vfs = require('node:vfs');

const provider = new vfs.MemoryProvider();
const myVfs = vfs.create(provider);
myVfs.writeFileSync('/seed.txt', 'initial');

provider.setReadOnly();

myVfs.writeFileSync('/x.txt', 'fail'); // throws EROFS