mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node/pull/12442 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: William Kapke <william.kapke@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>v6
Anna Henningsen
8 years ago
3 changed files with 46 additions and 2 deletions
@ -0,0 +1,31 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const { promisify } = require('util'); |
|||
|
|||
common.crashOnUnhandledRejection(); |
|||
|
|||
const read = promisify(fs.read); |
|||
const write = promisify(fs.write); |
|||
|
|||
{ |
|||
const fd = fs.openSync(__filename, 'r'); |
|||
read(fd, Buffer.alloc(1024), 0, 1024, null).then(common.mustCall((obj) => { |
|||
assert.strictEqual(typeof obj.bytesRead, 'number'); |
|||
assert(obj.buffer instanceof Buffer); |
|||
fs.closeSync(fd); |
|||
})); |
|||
} |
|||
|
|||
common.refreshTmpDir(); |
|||
{ |
|||
const filename = path.join(common.tmpDir, 'write-promise.txt'); |
|||
const fd = fs.openSync(filename, 'w'); |
|||
write(fd, Buffer.from('foobar')).then(common.mustCall((obj) => { |
|||
assert.strictEqual(typeof obj.bytesWritten, 'number'); |
|||
assert.strictEqual(obj.buffer.toString(), 'foobar'); |
|||
fs.closeSync(fd); |
|||
})); |
|||
} |
Loading…
Reference in new issue