1'use strict'; 2 3const { 4 ObjectSetPrototypeOf, 5} = primordials; 6 7const { Writable } = require('stream'); 8const { closeSync, writeSync } = require('fs'); 9 10function SyncWriteStream(fd, options) { 11 Writable.call(this, { autoDestroy: true }); 12 13 options = options || {}; 14 15 this.fd = fd; 16 this.readable = false; 17 this.autoClose = options.autoClose === undefined ? true : options.autoClose; 18} 19 20ObjectSetPrototypeOf(SyncWriteStream.prototype, Writable.prototype); 21ObjectSetPrototypeOf(SyncWriteStream, Writable); 22 23SyncWriteStream.prototype._write = function(chunk, encoding, cb) { 24 writeSync(this.fd, chunk, 0, chunk.length); 25 cb(); 26 return true; 27}; 28 29SyncWriteStream.prototype._destroy = function(err, cb) { 30 if (this.fd === null) // already destroy()ed 31 return cb(err); 32 33 if (this.autoClose) 34 closeSync(this.fd); 35 36 this.fd = null; 37 cb(err); 38}; 39 40SyncWriteStream.prototype.destroySoon = 41 SyncWriteStream.prototype.destroy; 42 43module.exports = SyncWriteStream; 44