* @typedef {object} Utf8StreamOptions * @property {string} [dest] - path to the file to write to * @property {number} [fd] - file descriptor to write to * @property {number} [minLength] - minimum length of the internal buffer before a write is triggered * @property {number} [maxLength] -
(options = kNullPrototype)
| 114 | * @param {Utf8StreamOptions} [options] |
| 115 | */ |
| 116 | constructor(options = kNullPrototype) { |
| 117 | validateObject(options, 'options'); |
| 118 | let { |
| 119 | fd, |
| 120 | } = options; |
| 121 | const { |
| 122 | dest, |
| 123 | minLength, |
| 124 | maxLength, |
| 125 | maxWrite, |
| 126 | periodicFlush, |
| 127 | sync, |
| 128 | append = true, |
| 129 | mkdir, |
| 130 | retryEAGAIN, |
| 131 | fsync, |
| 132 | contentMode = kContentModeUtf8, |
| 133 | mode, |
| 134 | // Provides for a custom fs implementation. Mostly useful for testing. |
| 135 | fs: overrideFs = kEmptyObject, |
| 136 | } = options; |
| 137 | |
| 138 | super(); |
| 139 | |
| 140 | fd ??= dest; |
| 141 | |
| 142 | validateObject(overrideFs, 'options.fs'); |
| 143 | this.#fs = { ...fs, ...overrideFs }; |
| 144 | validateFunction(this.#fs.write, 'options.fs.write'); |
| 145 | validateFunction(this.#fs.writeSync, 'options.fs.writeSync'); |
| 146 | validateFunction(this.#fs.fsync, 'options.fs.fsync'); |
| 147 | validateFunction(this.#fs.fsyncSync, 'options.fs.fsyncSync'); |
| 148 | validateFunction(this.#fs.close, 'options.fs.close'); |
| 149 | validateFunction(this.#fs.open, 'options.fs.open'); |
| 150 | validateFunction(this.#fs.mkdir, 'options.fs.mkdir'); |
| 151 | validateFunction(this.#fs.mkdirSync, 'options.fs.mkdirSync'); |
| 152 | |
| 153 | this.#hwm = MathMax(minLength || 0, this.#hwm); |
| 154 | this.#minLength = minLength || 0; |
| 155 | this.#maxLength = maxLength || 0; |
| 156 | this.#maxWrite = maxWrite || kMaxWrite; |
| 157 | this.#periodicFlush = periodicFlush || 0; |
| 158 | this.#sync = sync || false; |
| 159 | this.#fsync = fsync || false; |
| 160 | this.#append = append || false; |
| 161 | this.#mode = mode; |
| 162 | this.#retryEAGAIN = retryEAGAIN || (() => true); |
| 163 | this.#mkdir = mkdir || false; |
| 164 | |
| 165 | validateUint32(this.#hwm, 'options.hwm'); |
| 166 | validateUint32(this.#minLength, 'options.minLength'); |
| 167 | validateUint32(this.#maxLength, 'options.maxLength'); |
| 168 | validateUint32(this.#maxWrite, 'options.maxWrite'); |
| 169 | validateUint32(this.#periodicFlush, 'options.periodicFlush'); |
| 170 | validateBoolean(this.#sync, 'options.sync'); |
| 171 | validateBoolean(this.#fsync, 'options.fsync'); |
| 172 | validateBoolean(this.#append, 'options.append'); |
| 173 | validateBoolean(this.#mkdir, 'options.mkdir'); |
nothing calls this directly
no test coverage detected