11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst {
41cb0ef41Sopenharmony_ci  ObjectSetPrototypeOf,
51cb0ef41Sopenharmony_ci  ReflectApply,
61cb0ef41Sopenharmony_ci} = primordials;
71cb0ef41Sopenharmony_ciconst { kEmptyObject } = require('internal/util');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst { Writable } = require('stream');
101cb0ef41Sopenharmony_ciconst { closeSync, writeSync } = require('fs');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction SyncWriteStream(fd, options) {
131cb0ef41Sopenharmony_ci  ReflectApply(Writable, this, [{ autoDestroy: true }]);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  options = options || kEmptyObject;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  this.fd = fd;
181cb0ef41Sopenharmony_ci  this.readable = false;
191cb0ef41Sopenharmony_ci  this.autoClose = options.autoClose === undefined ? true : options.autoClose;
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciObjectSetPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
231cb0ef41Sopenharmony_ciObjectSetPrototypeOf(SyncWriteStream, Writable);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciSyncWriteStream.prototype._write = function(chunk, encoding, cb) {
261cb0ef41Sopenharmony_ci  try {
271cb0ef41Sopenharmony_ci    writeSync(this.fd, chunk, 0, chunk.length);
281cb0ef41Sopenharmony_ci  } catch (e) {
291cb0ef41Sopenharmony_ci    cb(e);
301cb0ef41Sopenharmony_ci    return;
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci  cb();
331cb0ef41Sopenharmony_ci};
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciSyncWriteStream.prototype._destroy = function(err, cb) {
361cb0ef41Sopenharmony_ci  if (this.fd === null) // already destroy()ed
371cb0ef41Sopenharmony_ci    return cb(err);
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  if (this.autoClose)
401cb0ef41Sopenharmony_ci    closeSync(this.fd);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  this.fd = null;
431cb0ef41Sopenharmony_ci  cb(err);
441cb0ef41Sopenharmony_ci};
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ciSyncWriteStream.prototype.destroySoon =
471cb0ef41Sopenharmony_ci  SyncWriteStream.prototype.destroy;
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_cimodule.exports = SyncWriteStream;
50