mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 10:45:51 +00:00

PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
ObjectSetPrototypeOf,
|
|
ReflectApply,
|
|
} = primordials;
|
|
const { kEmptyObject } = require('internal/util');
|
|
|
|
const { Writable } = require('stream');
|
|
const { closeSync, writeSync } = require('fs');
|
|
|
|
function SyncWriteStream(fd, options) {
|
|
ReflectApply(Writable, this, [{ autoDestroy: true }]);
|
|
|
|
options = options || kEmptyObject;
|
|
|
|
this.fd = fd;
|
|
this.readable = false;
|
|
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
|
|
}
|
|
|
|
ObjectSetPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
|
|
ObjectSetPrototypeOf(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;
|