1'use strict'; 2 3const common = require('../common'); 4const fs = require('fs'); 5const assert = require('assert'); 6 7const tmpdir = require('../common/tmpdir'); 8tmpdir.refresh(); 9 10{ 11 // Compat error. 12 13 function ReadStream(...args) { 14 fs.ReadStream.call(this, ...args); 15 } 16 Object.setPrototypeOf(ReadStream.prototype, fs.ReadStream.prototype); 17 Object.setPrototypeOf(ReadStream, fs.ReadStream); 18 19 ReadStream.prototype.open = common.mustCall(function ReadStream$open() { 20 const that = this; 21 fs.open(that.path, that.flags, that.mode, (err, fd) => { 22 that.emit('error', err); 23 }); 24 }); 25 26 const r = new ReadStream('/doesnotexist', { emitClose: true }) 27 .on('error', common.mustCall((err) => { 28 assert.strictEqual(err.code, 'ENOENT'); 29 assert.strictEqual(r.destroyed, true); 30 r.on('close', common.mustCall()); 31 })); 32} 33