forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-fs-promisified.js
More file actions
38 lines (33 loc) · 1020 Bytes
/
test-fs-promisified.js
File metadata and controls
38 lines (33 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'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 exists = promisify(fs.exists);
{
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);
}));
}
{
exists(__filename).then(common.mustCall((x) => {
assert.strictEqual(x, true);
}));
}