-
-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Description
Given the real dir structure
C:/
βββ src/
βββ file.txt
The following program without memfs
import { resolve } from 'path';
import { pathToFileURL } from 'url';
import { readdirSync, readFileSync } from 'fs';
console.log(resolve('/src'));
console.log(readdirSync(resolve('/src')));
console.log('string path:', readFileSync(resolve('/src/file.txt'), 'utf8'));
console.log(' file URL:', readFileSync(pathToFileURL(resolve('/src/file.txt')), 'utf8'));
Prints:
C:\src
[ 'file.txt' ]
string path: Hello from file!
file URL: Hello from file!
Using memfs, the equivalent program
import { resolve } from 'path';
import { pathToFileURL } from 'url';
import { fs, vol } from 'memfs';
vol.fromJSON({
'file.txt': 'Hello from fake file!'
}, resolve('/src'));
console.log(resolve('/src'));
console.log(fs.readdirSync(resolve('/src')));
console.log('string path:', fs.readFileSync(resolve('/src/file.txt'), 'utf8'));
console.log(' file URL:', fs.readFileSync(pathToFileURL(resolve('/src/file.txt')), 'utf8'));
Prints and throws:
C:\src
[ 'file.txt' ]
string path: Hello from fake file!
Error: ENOENT: no such file or directory, open '/C:/src/file.txt'
Metadata
Metadata
Assignees
Labels
No labels