mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
908292cf1f
PR-URL: https://github.com/nodejs/node/pull/27146 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
42 lines
953 B
JavaScript
42 lines
953 B
JavaScript
'use strict';
|
|
|
|
const { Object } = primordials;
|
|
|
|
const { Writable } = require('stream');
|
|
const { closeSync, writeSync } = require('fs');
|
|
|
|
function SyncWriteStream(fd, options) {
|
|
Writable.call(this, { autoDestroy: true });
|
|
|
|
options = options || {};
|
|
|
|
this.fd = fd;
|
|
this.readable = false;
|
|
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
|
|
}
|
|
|
|
Object.setPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
|
|
Object.setPrototypeOf(SyncWriteStream, Writable);
|
|
|
|
SyncWriteStream.prototype._write = function(chunk, encoding, cb) {
|
|
writeSync(this.fd, chunk, 0, chunk.length);
|
|
cb();
|
|
return true;
|
|
};
|
|
|
|
SyncWriteStream.prototype._destroy = function(err, cb) {
|
|
if (this.fd === null) // already destroy()ed
|
|
return cb(err);
|
|
|
|
if (this.autoClose)
|
|
closeSync(this.fd);
|
|
|
|
this.fd = null;
|
|
cb(err);
|
|
};
|
|
|
|
SyncWriteStream.prototype.destroySoon =
|
|
SyncWriteStream.prototype.destroy;
|
|
|
|
module.exports = SyncWriteStream;
|