• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const fs = require('fs');
4const path = require('path');
5const assert = require('assert');
6const tmpdir = require('../common/tmpdir');
7const file = path.join(tmpdir.path, 'write_stream_filehandle_test.txt');
8const input = 'hello world';
9
10tmpdir.refresh();
11
12fs.promises.open(file, 'w+').then((handle) => {
13  handle.on('close', common.mustCall());
14  const stream = fs.createWriteStream(null, { fd: handle });
15
16  stream.end(input);
17  stream.on('close', common.mustCall(() => {
18    const output = fs.readFileSync(file, 'utf-8');
19    assert.strictEqual(output, input);
20  }));
21}).then(common.mustCall());
22