forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-fs-read-buffer.ts
More file actions
33 lines (28 loc) · 1.02 KB
/
node-fs-read-buffer.ts
File metadata and controls
33 lines (28 loc) · 1.02 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
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() {
var filepath = path.join(common.fixturesDir, 'x.txt'),
expected = 'xyz\n',
bufferAsync = new Buffer(expected.length),
bufferSync = new Buffer(expected.length),
readCalled = 0,
rootFS = fs.getRootFS();
fs.open(filepath, 'r', function(err, fd) {
if (err) throw err;
fs.read(fd, bufferAsync, 0, expected.length, 0, function(err, bytesRead) {
readCalled++;
assert.equal(bytesRead, expected.length);
assert.equal(bufferAsync.toString(), new Buffer(expected).toString());
});
if (rootFS.supportsSynch()) {
var r = fs.readSync(fd, bufferSync, 0, expected.length, 0);
assert.equal(bufferSync.toString(), new Buffer(expected).toString());
assert.equal(r, expected.length);
}
});
process.on('exit', function() {
assert.equal(readCalled, 1);
});
};