forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-fs-write-buffer.ts
More file actions
40 lines (34 loc) · 1.1 KB
/
node-fs-write-buffer.ts
File metadata and controls
40 lines (34 loc) · 1.1 KB
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
39
40
import fs from '../../../../src/core/node_fs';
import * as path from 'path';
import assert from '../../../harness/wrapped-assert';
import common from '../../../harness/common';
export default function() {
if (!fs.getRootFS().isReadOnly()) {
var filename = path.join(common.tmpDir, 'write.txt'),
expected = new Buffer('hello'),
openCalled = 0,
writeCalled = 0;
fs.open(filename, 'w', 0o644, function(err, fd) {
openCalled++;
if (err) throw err;
fs.write(fd, expected, 0, expected.length, null, function(err, written) {
writeCalled++;
if (err) throw err;
assert.equal(expected.length, written);
fs.close(fd, function(err) {
if (err) throw err;
fs.readFile(filename, 'utf8', function(err, found) {
assert.deepEqual(expected.toString(), found);
fs.unlink(filename, function(err) {
if (err) throw err;
});
});
});
});
});
process.on('exit', function() {
assert.equal(1, openCalled);
assert.equal(1, writeCalled);
});
}
};