/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/internal/fs/sync_write_stream.js
49 строк
1 KB
Livia Medeiros
lib: prefer `call()` over `apply()` if argument list is not array
23 ноя 2025, 11:45
Не верифицирован
23 ноя 2025, 11:45
46dc5d7
Код
Авторство
О чём код?
'use strict'; const { FunctionPrototypeCall, ObjectSetPrototypeOf, } = primordials; const { kEmptyObject } = require('internal/util'); const { Writable } = require('stream'); const { closeSync, writeSync } = require('fs'); function SyncWriteStream(fd, options) { FunctionPrototypeCall(Writable, this, { autoDestroy: true }); 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) { try { writeSync(this.fd, chunk, 0, chunk.length); } catch (e) { cb(e); return; } cb(); }; 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;