All files / lib/internal/fs sync_write_stream.js

100% Statements 44/44
87.5% Branches 7/8
100% Functions 3/3
100% Lines 44/44

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4531x 31x 31x 31x 31x 31x 31x 31x 31x 31x 2416x 2416x 2416x 2416x 2416x 2416x 2416x 2416x 2416x 31x 31x 31x 31x 31x 43592x 43592x 43592x 31x 31x 31x 3x 3x 3x 3x 3x 3x 3x 3x 31x 31x 31x 31x 31x 31x  
'use strict';
 
const {
  ObjectSetPrototypeOf,
  ReflectApply,
} = primordials;
 
const { Writable } = require('stream');
const { closeSync, writeSync } = require('fs');
 
function SyncWriteStream(fd, options) {
  ReflectApply(Writable, this, [{ autoDestroy: true }]);
 
  options = options || {};
 
  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;