summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-read-stream-fd.js
blob: a9ff56ee93fd910db0955c7381537313967df320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
const file = path.join(common.tmpDir, '/read_stream_fd_test.txt');
const input = 'hello world';

let output = '';
common.refreshTmpDir();
fs.writeFileSync(file, input);

const fd = fs.openSync(file, 'r');
const stream = fs.createReadStream(null, { fd: fd, encoding: 'utf8' });

stream.on('data', (data) => {
  output += data;
});

process.on('exit', () => {
  assert.strictEqual(output, input);
});