11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst fs = require('fs');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
71cb0ef41Sopenharmony_citmpdir.refresh();
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci{
101cb0ef41Sopenharmony_ci  const stream = fs.createReadStream(__filename);
111cb0ef41Sopenharmony_ci  stream.on('close', common.mustCall());
121cb0ef41Sopenharmony_ci  test(stream);
131cb0ef41Sopenharmony_ci}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci{
161cb0ef41Sopenharmony_ci  const stream = fs.createWriteStream(`${tmpdir.path}/dummy`);
171cb0ef41Sopenharmony_ci  stream.on('close', common.mustCall());
181cb0ef41Sopenharmony_ci  test(stream);
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci{
221cb0ef41Sopenharmony_ci  const stream = fs.createReadStream(__filename, { emitClose: true });
231cb0ef41Sopenharmony_ci  stream.on('close', common.mustCall());
241cb0ef41Sopenharmony_ci  test(stream);
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci{
281cb0ef41Sopenharmony_ci  const stream = fs.createWriteStream(`${tmpdir.path}/dummy2`,
291cb0ef41Sopenharmony_ci                                      { emitClose: true });
301cb0ef41Sopenharmony_ci  stream.on('close', common.mustCall());
311cb0ef41Sopenharmony_ci  test(stream);
321cb0ef41Sopenharmony_ci}
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_cifunction test(stream) {
361cb0ef41Sopenharmony_ci  const err = new Error('DESTROYED');
371cb0ef41Sopenharmony_ci  stream.on('open', function() {
381cb0ef41Sopenharmony_ci    stream.destroy(err);
391cb0ef41Sopenharmony_ci  });
401cb0ef41Sopenharmony_ci  stream.on('error', common.mustCall(function(err_) {
411cb0ef41Sopenharmony_ci    assert.strictEqual(err_, err);
421cb0ef41Sopenharmony_ci  }));
431cb0ef41Sopenharmony_ci}
44