MCPcopy Index your code
hub / github.com/nodejs/node / ReadableState

Function ReadableState

lib/internal/streams/readable.js:269–319  ·  view source on GitHub ↗
(options, stream, isDuplex)

Source from the content-addressed store, hash-verified

267
268
269function ReadableState(options, stream, isDuplex) {
270 // Bit map field to store ReadableState more efficiently with 1 bit per field
271 // instead of a V8 slot per field.
272 this[kState] = kEmitClose | kAutoDestroy | kConstructed | kSync;
273
274 // Object stream flag. Used to make read(n) ignore n and to
275 // make all the buffer merging and length checks go away.
276 if (options?.objectMode)
277 this[kState] |= kObjectMode;
278
279 if (isDuplex && options?.readableObjectMode)
280 this[kState] |= kObjectMode;
281
282 // The point at which it stops calling _read() to fill the buffer
283 // Note: 0 is a valid value, means "don't call _read preemptively ever"
284 this.highWaterMark = options ?
285 getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex) :
286 getDefaultHighWaterMark(false);
287
288 this.buffer = [];
289 this.bufferIndex = 0;
290 this.length = 0;
291 this.pipes = [];
292
293 // Should close be emitted on destroy. Defaults to true.
294 if (options && options.emitClose === false) this[kState] &= ~kEmitClose;
295
296 // Should .destroy() be called after 'end' (and potentially 'finish').
297 if (options && options.autoDestroy === false) this[kState] &= ~kAutoDestroy;
298
299 // Crypto is kind of old and crusty. Historically, its default string
300 // encoding is 'binary' so we have to make this configurable.
301 // Everything else in the universe uses 'utf8', though.
302 const defaultEncoding = options?.defaultEncoding;
303 if (defaultEncoding == null || defaultEncoding === 'utf8' || defaultEncoding === 'utf-8') {
304 this[kState] |= kDefaultUTF8Encoding;
305 } else if (Buffer.isEncoding(defaultEncoding)) {
306 this.defaultEncoding = defaultEncoding;
307 } else {
308 throw new ERR_UNKNOWN_ENCODING(defaultEncoding);
309 }
310
311 // Ref the piped dest which we need a drain event on it
312 // type: null | Writable | Set<Writable>.
313 this.awaitDrainWriters = null;
314
315 if (options?.encoding) {
316 this.decoder = new StringDecoder(options.encoding);
317 this.encoding = options.encoding;
318 }
319}
320
321ReadableState.prototype[kOnConstructed] = function onConstructed(stream) {
322 if ((this[kState] & kNeedReadable) !== 0) {

Callers

nothing calls this directly

Calls 2

getHighWaterMarkFunction · 0.85
getDefaultHighWaterMarkFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…