Created
June 18, 2017 14:02
-
-
Save franher/11411171213d0537ef48fc0bc6d07bd2 to your computer and use it in GitHub Desktop.
fs.read promisified version
This file contains 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
const { promisify } = require('util'); | |
const { read, open } = require('fs'); | |
const readPromisified = promisify(read); | |
const openPromisified = promisify(open); | |
const expected = Buffer.from('xyz\n'); | |
const buffer = Buffer.allocUnsafe(expected.length); | |
openPromisified('x.txt', 'r').then(fd => { | |
readPromisified(fd, buffer, 0, expected.length, 0).then(obj => { | |
console.log(obj); | |
// { bytesRead: 3, buffer: <Buffer 78 79 7a 03> } | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment