fs-promise-lite
v1.0.0
Published
the version promise of fs
Downloads
2
Readme
Installation
npm install --save fs-promise-lite
npm install --save-dev fs-promise-lite
Utilisation
the same api with original fs
const fs = require('fs-promise-lite')
fs.readFile('file1.txt','utf8')
.then((data) => {
console.log(data)
})
Supported
fs.readdir(dir,options)
fs.readFile(file,options)
fs.stat(file)
fs.writeFile(file,data,options)
fs.unlink(file)
fs.mkdir(dirname,mode)
fs.rmdir(dirname)
fs.appendFile(file,data,options)
fs.chmod(path,mode)
fs.chown(path,uid,gid)
fs.symlink(target,path,type)
Exceptional
- readFiles(fileArr,options) - read many files
const fs = require('fs-promise-lite')
let arr = ['file1.txt','file2.txt','file3.txt']
Promise.all(fs.readFiles(arr,'utf8'))
.then(console.log)
// [['file1.txt','data1'],['file2.txt','data2'],['file3.txt','data3']]
- unlinks(fileArr) - delete many files
const fs = require('fs-promise-lite')
let arr = ['file1.txt','file2.txt','file3.txt']
Promise.all(fs.unlinks(arr))
.then(() => {
console.log('ok')
})
- writeFiles(files_datas,options)
const fs = require('fs-promise-lite')
let files_datas = [
['file1.txt','data1'],
['file2.txt','data2'],
['file3.txt','data3']
]
Promise.all(fs.writeFiles(files_datas,'utf8'))
.then(() => {
console.log('ok')
})
- stats(files)
const fs = require('fs-promise-lite')
let arr = ['file1.txt','file2.txt','file3.txt']
Promise.all(fs.stats(arr))
.then(console.log)
/*
[['file1.txt',Object_stat1],['file2.txt',Object_stat2],['file3.txt',Object_stat3]]
which Object_stats is like:
Stats {
dev: 66311,
mode: 33188,
nlink: 1,
uid: 0,
gid: 0,
rdev: 0,
blksize: 4096,
ino: 3288667,
size: 202,
blocks: 8,
atimeMs: 1507047059530.785,
mtimeMs: 1507047058318.7754,
ctimeMs: 1507047058326.7754,
birthtimeMs: 1507047058326.7754,
atime: 2017-10-03T16:10:59.531Z,
mtime: 2017-10-03T16:10:58.319Z,
ctime: 2017-10-03T16:10:58.327Z,
birthtime: 2017-10-03T16:10:58.327Z
}
*/