forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-fs-write.ts
More file actions
53 lines (50 loc) · 1.84 KB
/
node-fs-write.ts
File metadata and controls
53 lines (50 loc) · 1.84 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
41
42
43
44
45
46
47
48
49
50
51
52
53
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 fn = path.join(common.tmpDir, 'write.txt');
var fn2 = path.join(common.tmpDir, 'write2.txt');
var expected = 'ümlaut.';
fs.open(fn, 'w', 0o644, function(err, fd) {
if (err) throw err;
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
});
fs.write(fd, expected, 0, 'utf8', function(err, written) {
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
fs.close(fd, function(err) {
if (err) throw err;
fs.readFile(fn, 'utf8', function(err, data) {
if (err) throw err;
assert.equal(expected, data,
'expected: "' + data + '", found: "' + data + '"');
fs.unlink(fn, function(err) { if (err) throw err; });
});
});
});
});
fs.open(fn2, 'w', 0o644,
function(err, fd) {
if (err) throw err;
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
});
fs.write(fd, expected, 0, 'utf8', function(err, written) {
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
fs.close(fd, function(err) {
if (err) throw err;
fs.readFile(fn2, 'utf8', function(err, data) {
if (err) throw err;
assert.equal(expected, data,
'expected: "' + expected + '", found: "' + data + '"');
fs.unlink(fn2, function(err) { if (err) throw err; });
});
});
});
});
}
};