Packages

class Readable extends Object with StObject with ReadableStream

Annotations
@JSType() @JSImport("stream", "Readable") @native()
Since

v0.9.4

Linear Supertypes
ReadableStream, EventEmitter, StObject, Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Readable
  2. ReadableStream
  3. EventEmitter
  4. StObject
  5. Object
  6. Any
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Readable(opts: ReadableOptions)
  2. new Readable()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. var _construct: UndefOr[Function1[Function1[UndefOr[|[Error, Null]], Unit], Unit]]
  5. def _destroy(error: Null, callback: Function1[UndefOr[|[Error, Null]], Unit]): Unit
  6. def _destroy(error: Error, callback: Function1[UndefOr[|[Error, Null]], Unit]): Unit
  7. def _read(size: Double): Unit
  8. def addListener(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  9. def addListener(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Alias for emitter.on(eventName, listener).

    Alias for emitter.on(eventName, listener).

    Definition Classes
    EventEmitter
    Since

    v0.1.26

  10. def addListener_close(event: close, listener: Function0[Unit]): Readable.this.type

    Event emitter The defined events on documents including: 1.

    Event emitter The defined events on documents including: 1. close 2. data 3. end 4. error 5. pause 6. readable 7. resume

    Annotations
    @JSName("addListener")
  11. def addListener_data(event: data, listener: Function1[Any, Unit]): Readable.this.type
    Annotations
    @JSName("addListener")
  12. def addListener_end(event: end, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("addListener")
  13. def addListener_error(event: error, listener: Function1[Error, Unit]): Readable.this.type
    Annotations
    @JSName("addListener")
  14. def addListener_pause(event: pause, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("addListener")
  15. def addListener_readable(event: readable, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("addListener")
  16. def addListener_resume(event: resume, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("addListener")
  17. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  18. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  19. def destroy(error: Error): Unit
  20. def destroy(): Unit

    Destroy the stream.

    Destroy the stream. Optionally emit an 'error' event, and emit a 'close'event (unless emitClose is set to false). After this call, the readable stream will release any internal resources and subsequent calls to push()will be ignored.

    Once destroy() has been called any further calls will be a no-op and no further errors except from _destroy() may be emitted as 'error'.

    Implementors should not override this method, but instead implement readable._destroy().

    Since

    v8.0.0

  21. var destroyed: Boolean

    Is true after readable.destroy() has been called.

    Is true after readable.destroy() has been called.

    Since

    v8.0.0

  22. def emit(eventName: Symbol, args: Any*): Boolean
    Definition Classes
    EventEmitter
  23. def emit(eventName: String, args: Any*): Boolean

    Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

    Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

    Returns true if the event had listeners, false otherwise.

    js const EventEmitter = require('events'); const myEmitter = new EventEmitter();

    // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(event with parameters ${arg1}, ${arg2} in second listener); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(event with parameters ${parameters} in third listener); });

    console.log(myEmitter.listeners('event'));

    myEmitter.emit('event', 1, 2, 3, 4, 5);

    // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener

    Definition Classes
    EventEmitter
    Since

    v0.1.26

  24. def emit_close(event: close): Boolean
    Annotations
    @JSName("emit")
  25. def emit_data(event: data, chunk: Any): Boolean
    Annotations
    @JSName("emit")
  26. def emit_end(event: end): Boolean
    Annotations
    @JSName("emit")
  27. def emit_error(event: error, err: Error): Boolean
    Annotations
    @JSName("emit")
  28. def emit_pause(event: pause): Boolean
    Annotations
    @JSName("emit")
  29. def emit_readable(event: readable): Boolean
    Annotations
    @JSName("emit")
  30. def emit_resume(event: resume): Boolean
    Annotations
    @JSName("emit")
  31. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  33. def eventNames(): Array[|[String, Symbol]]

    Returns an array listing the events for which the emitter has registered listeners.

    Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

    js const EventEmitter = require('events'); const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {});

    const sym = Symbol('symbol'); myEE.on(sym, () => {});

    console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ]

    Definition Classes
    EventEmitter
    Since

    v6.0.0

  34. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  35. def getMaxListeners(): Double

    Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

    Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

    Definition Classes
    EventEmitter
    Since

    v1.0.0

  36. def hasOwnProperty(v: String): Boolean
    Definition Classes
    Object
  37. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  38. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  39. def isPaused(): Boolean
    Definition Classes
    ReadableStream
  40. def isPrototypeOf(v: Object): Boolean
    Definition Classes
    Object
  41. def listenerCount(eventName: Symbol): Double
    Definition Classes
    EventEmitter
  42. def listenerCount(eventName: String): Double

    Returns the number of listeners listening to the event named eventName.

    Returns the number of listeners listening to the event named eventName.

    eventName

    The name of the event being listened for

    Definition Classes
    EventEmitter
    Since

    v3.2.0

  43. def listeners(eventName: Symbol): Array[Function]
    Definition Classes
    EventEmitter
  44. def listeners(eventName: String): Array[Function]

    Returns a copy of the array of listeners for the event named eventName.

    Returns a copy of the array of listeners for the event named eventName.

    js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ]

    Definition Classes
    EventEmitter
    Since

    v0.1.26

  45. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  46. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  47. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  48. def off(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  49. def off(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Alias for emitter.removeListener().

    Alias for emitter.removeListener().

    Definition Classes
    EventEmitter
    Since

    v10.0.0

  50. def on(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  51. def on(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Adds the listener function to the end of the listeners array for the event named eventName.

    Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple times.

    js server.on('connection', (stream) => { console.log('someone connected!'); });

    Returns a reference to the EventEmitter, so that calls can be chained.

    By default, event listeners are invoked in the order they are added. Theemitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

    js const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a

    eventName

    The name of the event.

    listener

    The callback function

    Definition Classes
    EventEmitter
    Since

    v0.1.101

  52. def on_close(event: close, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("on")
  53. def on_data(event: data, listener: Function1[Any, Unit]): Readable.this.type
    Annotations
    @JSName("on")
  54. def on_end(event: end, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("on")
  55. def on_error(event: error, listener: Function1[Error, Unit]): Readable.this.type
    Annotations
    @JSName("on")
  56. def on_pause(event: pause, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("on")
  57. def on_readable(event: readable, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("on")
  58. def on_resume(event: resume, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("on")
  59. def once(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  60. def once(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Adds a **one-time**listener function for the event named eventName.

    Adds a **one-time**listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

    js server.once('connection', (stream) => { console.log('Ah, we have our first user!'); });

    Returns a reference to the EventEmitter, so that calls can be chained.

    By default, event listeners are invoked in the order they are added. Theemitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

    js const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a

    eventName

    The name of the event.

    listener

    The callback function

    Definition Classes
    EventEmitter
    Since

    v0.3.0

  61. def once_close(event: close, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("once")
  62. def once_data(event: data, listener: Function1[Any, Unit]): Readable.this.type
    Annotations
    @JSName("once")
  63. def once_end(event: end, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("once")
  64. def once_error(event: error, listener: Function1[Error, Unit]): Readable.this.type
    Annotations
    @JSName("once")
  65. def once_pause(event: pause, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("once")
  66. def once_readable(event: readable, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("once")
  67. def once_resume(event: resume, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("once")
  68. def pause(): Readable.this.type
    Definition Classes
    ReadableStream
  69. def pipe[T](destination: T, options: End): T
    Definition Classes
    ReadableStream
  70. def pipe[T](destination: T): T
    Definition Classes
    ReadableStream
  71. def prependListener(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  72. def prependListener(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Adds the listener function to the _beginning_ of the listeners array for the event named eventName.

    Adds the listener function to the _beginning_ of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple times.

    js server.prependListener('connection', (stream) => { console.log('someone connected!'); });

    Returns a reference to the EventEmitter, so that calls can be chained.

    eventName

    The name of the event.

    listener

    The callback function

    Definition Classes
    EventEmitter
    Since

    v6.0.0

  73. def prependListener_close(event: close, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  74. def prependListener_data(event: data, listener: Function1[Any, Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  75. def prependListener_end(event: end, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  76. def prependListener_error(event: error, listener: Function1[Error, Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  77. def prependListener_pause(event: pause, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  78. def prependListener_readable(event: readable, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  79. def prependListener_resume(event: resume, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependListener")
  80. def prependOnceListener(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  81. def prependOnceListener(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Adds a **one-time**listener function for the event named eventName to the_beginning_ of the listeners array.

    Adds a **one-time**listener function for the event named eventName to the_beginning_ of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

    js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });

    Returns a reference to the EventEmitter, so that calls can be chained.

    eventName

    The name of the event.

    listener

    The callback function

    Definition Classes
    EventEmitter
    Since

    v6.0.0

  82. def prependOnceListener_close(event: close, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  83. def prependOnceListener_data(event: data, listener: Function1[Any, Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  84. def prependOnceListener_end(event: end, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  85. def prependOnceListener_error(event: error, listener: Function1[Error, Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  86. def prependOnceListener_pause(event: pause, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  87. def prependOnceListener_readable(event: readable, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  88. def prependOnceListener_resume(event: resume, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("prependOnceListener")
  89. def propertyIsEnumerable(v: String): Boolean
    Definition Classes
    Object
  90. def push(chunk: Any, encoding: BufferEncoding): Boolean
  91. def push(chunk: Any): Boolean
  92. def rawListeners(eventName: Symbol): Array[Function]
    Definition Classes
    EventEmitter
  93. def rawListeners(eventName: String): Array[Function]

    Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

    Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

    js const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once'));

    // Returns a new Array with a function onceWrapper which has a property // listener which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0];

    // Logs "log once" to the console and does not unbind the once event logFnWrapper.listener();

    // Logs "log once" to the console and removes the listener logFnWrapper();

    emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by .on() above const newListeners = emitter.rawListeners('log');

    // Logs "log persistently" twice newListeners[0](); emitter.emit('log');

    Definition Classes
    EventEmitter
    Since

    v9.4.0

  94. def read(size: Double): |[String, Buffer]
    Definition Classes
    ReadableStream
  95. def read(): |[String, Buffer]
    Definition Classes
    ReadableStream
  96. val readable: Boolean
    Definition Classes
    ReadableStream
  97. val readableAborted: Boolean

    Returns whether the stream was destroyed or errored before emitting 'end'.

    Returns whether the stream was destroyed or errored before emitting 'end'.

    Since

    v16.8.0

  98. val readableDidRead: Boolean

    Returns whether 'data' has been emitted.

    Returns whether 'data' has been emitted.

    Since

    v16.7.0

  99. val readableEncoding: |[BufferEncoding, Null]

    Getter for the property encoding of a given Readable stream.

    Getter for the property encoding of a given Readable stream. The encodingproperty can be set using the readable.setEncoding() method.

    Since

    v12.7.0

  100. val readableEnded: Boolean

    Becomes true when 'end' event is emitted.

    Becomes true when 'end' event is emitted.

    Since

    v12.9.0

  101. val readableFlowing: |[Boolean, Null]

    This property reflects the current state of a Readable stream as described in the Three states section.

    This property reflects the current state of a Readable stream as described in the Three states section.

    Since

    v9.4.0

  102. val readableHighWaterMark: Double

    Returns the value of highWaterMark passed when creating this Readable.

    Returns the value of highWaterMark passed when creating this Readable.

    Since

    v9.3.0

  103. val readableLength: Double

    This property contains the number of bytes (or objects) in the queue ready to be read.

    This property contains the number of bytes (or objects) in the queue ready to be read. The value provides introspection data regarding the status of the highWaterMark.

    Since

    v9.4.0

  104. val readableObjectMode: Boolean

    Getter for the property objectMode of a given Readable stream.

    Getter for the property objectMode of a given Readable stream.

    Since

    v12.3.0

  105. def removeAllListeners(event: Symbol): Readable.this.type
    Definition Classes
    EventEmitter
  106. def removeAllListeners(event: String): Readable.this.type
    Definition Classes
    EventEmitter
  107. def removeAllListeners(): Readable.this.type

    Removes all listeners, or those of the specified eventName.

    Removes all listeners, or those of the specified eventName.

    It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

    Returns a reference to the EventEmitter, so that calls can be chained.

    Definition Classes
    EventEmitter
    Since

    v0.1.26

  108. def removeListener(eventName: Symbol, listener: Function1[Any, Unit]): Readable.this.type
    Definition Classes
    EventEmitter
  109. def removeListener(eventName: String, listener: Function1[Any, Unit]): Readable.this.type

    Removes the specified listener from the listener array for the event namedeventName.

    Removes the specified listener from the listener array for the event namedeventName.

    js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback);

    removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

    Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that anyremoveListener() or removeAllListeners() calls _after_ emitting and_before_ the last listener finishes execution will not remove them fromemit() in progress. Subsequent events behave as expected.

    js const myEmitter = new MyEmitter();

    const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); };

    const callbackB = () => { console.log('B'); };

    myEmitter.on('event', callbackA);

    myEmitter.on('event', callbackB);

    // callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B

    // callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A

    Because listeners are managed using an internal array, calling this will change the position indices of any listener registered _after_ the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

    When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping')listener is removed:

    js const ee = new EventEmitter();

    function pong() { console.log('pong'); }

    ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong);

    ee.emit('ping'); ee.emit('ping');

    Returns a reference to the EventEmitter, so that calls can be chained.

    Definition Classes
    EventEmitter
    Since

    v0.1.26

  110. def removeListener_close(event: close, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  111. def removeListener_data(event: data, listener: Function1[Any, Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  112. def removeListener_end(event: end, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  113. def removeListener_error(event: error, listener: Function1[Error, Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  114. def removeListener_pause(event: pause, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  115. def removeListener_readable(event: readable, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  116. def removeListener_resume(event: resume, listener: Function0[Unit]): Readable.this.type
    Annotations
    @JSName("removeListener")
  117. def resume(): Readable.this.type
    Definition Classes
    ReadableStream
  118. def setEncoding(encoding: BufferEncoding): Readable.this.type
    Definition Classes
    ReadableStream
  119. def setMaxListeners(n: Double): Readable.this.type

    By default EventEmitters will print a warning if more than 10 listeners are added for a particular event.

    By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.

    Returns a reference to the EventEmitter, so that calls can be chained.

    Definition Classes
    EventEmitter
    Since

    v0.3.5

  120. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  121. def toLocaleString(): String
    Definition Classes
    Object
  122. def toString(): String
    Definition Classes
    AnyRef → Any
  123. def unpipe(destination: WritableStream): Readable.this.type
    Definition Classes
    ReadableStream
  124. def unpipe(): Readable.this.type
    Definition Classes
    ReadableStream
  125. def unshift(chunk: Any, encoding: BufferEncoding): Unit
  126. def unshift(chunk: Any): Unit

    Passing chunk as null signals the end of the stream (EOF) and behaves the same as readable.push(null), after which no more data can be written.

    Passing chunk as null signals the end of the stream (EOF) and behaves the same as readable.push(null), after which no more data can be written. The EOF signal is put at the end of the buffer and any buffered data will still be flushed.

    The readable.unshift() method pushes a chunk of data back into the internal buffer. This is useful in certain situations where a stream is being consumed by code that needs to "un-consume" some amount of data that it has optimistically pulled out of the source, so that the data can be passed on to some other party.

    The stream.unshift(chunk) method cannot be called after the 'end' event has been emitted or a runtime error will be thrown.

    Developers using stream.unshift() often should consider switching to use of a Transform stream instead. See the API for stream implementers section for more information.

    js // Pull off a header delimited by \n\n. // Use unshift() if we get too much. // Call the callback with (error, header, stream). const { StringDecoder } = require('string_decoder'); function parseHeader(stream, callback) { stream.on('error', callback); stream.on('readable', onReadable); const decoder = new StringDecoder('utf8'); let header = ; function onReadable() { let chunk; while (null !== (chunk = stream.read())) { const str = decoder.write(chunk); if (str.match(/\n\n/)) { // Found the header boundary. const split = str.split(/\n\n/); header += split.shift(); const remaining = split.join('\n\n'); const buf = Buffer.from(remaining, 'utf8'); stream.removeListener('error', callback); // Remove the 'readable' listener before unshifting. stream.removeListener('readable', onReadable); if (buf.length) stream.unshift(buf); // Now the body of the message can be read from the stream. callback(null, header, stream); } else { // Still reading the header. header += str; } } } }

    Unlike push, stream.unshift(chunk) will not end the reading process by resetting the internal reading state of the stream. This can cause unexpected results if readable.unshift() is called during a read (i.e. from within a _read implementation on a custom stream). Following the call to readable.unshift() with an immediate push will reset the reading state appropriately, however it is best to simply avoid calling readable.unshift() while in the process of performing a read.

    chunk

    Chunk of data to unshift onto the read queue. For streams not operating in object mode, chunk must be a string, Buffer, Uint8Array or null. For object mode streams, chunk may be any JavaScript value.

    Since

    v0.9.11

  127. def unshift(chunk: Uint8Array, encoding: BufferEncoding): Unit
    Definition Classes
    ReadableStream
  128. def unshift(chunk: Uint8Array): Unit
    Definition Classes
    ReadableStream
  129. def unshift(chunk: String, encoding: BufferEncoding): Unit
    Definition Classes
    ReadableStream
  130. def unshift(chunk: String): Unit
    Definition Classes
    ReadableStream
  131. def valueOf(): Any
    Definition Classes
    Object
  132. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  133. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  134. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  135. def wrap(oldStream: ReadableStream): Readable.this.type
    Definition Classes
    ReadableStream

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from ReadableStream

Inherited from EventEmitter

Inherited from StObject

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped