diff options
author | Matteo Collina <hello@matteocollina.com> | 2019-03-15 19:58:42 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2019-03-18 10:30:07 +0100 |
commit | abafd38c8d4e1a280f97ea452688cda54424d185 (patch) | |
tree | b4ee9333cc9d03a26fdf7b5ec6d938cb2a921c8a /lib/internal/fs/sync_write_stream.js | |
parent | 36101558fd9f8d5079d780930d97eb44bac479c9 (diff) | |
download | android-node-v8-abafd38c8d4e1a280f97ea452688cda54424d185.tar.gz android-node-v8-abafd38c8d4e1a280f97ea452688cda54424d185.tar.bz2 android-node-v8-abafd38c8d4e1a280f97ea452688cda54424d185.zip |
fs: use proper .destroy() implementation for SyncWriteStream
PR-URL: https://github.com/nodejs/node/pull/26690
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/fs/sync_write_stream.js')
-rw-r--r-- | lib/internal/fs/sync_write_stream.js | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/internal/fs/sync_write_stream.js b/lib/internal/fs/sync_write_stream.js index 1e7c6a50a9..0af289d7f4 100644 --- a/lib/internal/fs/sync_write_stream.js +++ b/lib/internal/fs/sync_write_stream.js @@ -4,15 +4,13 @@ const { Writable } = require('stream'); const { closeSync, writeSync } = require('fs'); function SyncWriteStream(fd, options) { - Writable.call(this); + Writable.call(this, { autoDestroy: true }); options = options || {}; this.fd = fd; this.readable = false; this.autoClose = options.autoClose === undefined ? true : options.autoClose; - - this.on('end', () => this._destroy()); } Object.setPrototypeOf(SyncWriteStream.prototype, Writable.prototype); @@ -24,22 +22,18 @@ SyncWriteStream.prototype._write = function(chunk, encoding, cb) { return true; }; -SyncWriteStream.prototype._destroy = function() { +SyncWriteStream.prototype._destroy = function(err, cb) { if (this.fd === null) // already destroy()ed - return; + return cb(err); if (this.autoClose) closeSync(this.fd); this.fd = null; - return true; + cb(err); }; SyncWriteStream.prototype.destroySoon = -SyncWriteStream.prototype.destroy = function() { - this._destroy(); - this.emit('close'); - return true; -}; + SyncWriteStream.prototype.destroy; module.exports = SyncWriteStream; |