Last active
December 24, 2015 16:10
-
-
Save yamafaktory/0412a7753da948b25e05 to your computer and use it in GitHub Desktop.
Simple IO module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function () { | |
'use strict' | |
/* | |
Simple IO module. | |
*/ | |
module.exports = IO | |
const fs = require('fs') | |
IO.prototype.create = path => { | |
return new Promise((res, rej) => { | |
fs.open(path, 'w', e => { | |
if (e) rej(e) | |
res() | |
}) | |
}) | |
} | |
IO.prototype.remove = path => { | |
return new Promise((res, rej) => { | |
fs.unlink(path, e => { | |
if (e) rej(e) | |
res() | |
}) | |
}) | |
} | |
IO.prototype.read = path => { | |
return new Promise((res, rej) => { | |
fs.readFile(path, 'utf8', (e, data) => { | |
if (e) rej(e) | |
res(data) | |
}) | |
}) | |
} | |
IO.prototype.write = (path, data) => { | |
return new Promise((res, rej) => { | |
fs.writeFile(path, data, e => { | |
if (e) rej(e) | |
res() | |
}) | |
}) | |
} | |
function IO () {} | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic usage: