Read a file or directory into a vfile.
Read a file or directory into avfilewhile keeping the directories structure using vfiles contents key. Vfile-read returns a promise if no callback is given.
npm i vfile-read
Given:
./foo
|_bar
|_foo.txt
|_"Foo"
varread=require('vfile-read')
read('./foo')
.then(console.log)
.catch(console.error)
Outputs:
VFile{
data:{},
messages:[],
history:['foo'],
cwd:'./',
contents:[
VFile{
data:{},
messages:[],
history:["foo/bar"],
cwd:"./",
contents:[
VFile{
data:{},
messages:[],
history:["foo/bar/foo.txt"],
cwd:"./",
contents:"Foo"
}
]
}
]
}
string
- Location to read from.
[string
|array
|object
] - If options is a string then options.encoding is set to options. If options is an array then options.ignores is set to options.
string- default = 'utf-8'
array- default = []
function
- If no callback is given, then read returns a promise.
Synchronous version of vfile-read
varread=require('vfile-read')
try{
varfile=read.sync('./',{ignores:['node_modules'])
...
}catch(err){
...
}
Vfile-read uses fs.readdir and fs.readFile and options will be passed down to those functions.
to-vfile- Create a vfile from a file-path
MIT © Paul Zimmer