Skip to content

Instantly share code, notes, and snippets.

@popovkos
Last active August 2, 2019 08:04
Show Gist options
  • Save popovkos/399a47b137ee0b99808ad4cc35a47da7 to your computer and use it in GitHub Desktop.
Save popovkos/399a47b137ee0b99808ad4cc35a47da7 to your computer and use it in GitHub Desktop.
const fs=require('fs');
const ab=['access','rename','ftruncate','chown','lchown','cmod','fchmod','stat','lstat','fstat','link','symlink',
'readlink','realpath','unlink','rmdir','readdir','close','open','utimes',
'futimes','fsync','write','read','readFile','writeFile','appendFile','mkdir','mkdtemp']
// fchown fdatasync mkdtemp rename truncate
ab.forEach(name=>{
if(!fs[name])return;
exports[name]=(...n)=>{
return new Promise((res,rej)=>{
fs[name](...n,(er,d)=>{
if(er)rej(er)
if(d)res(d)
})
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment