PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /opt/alt/alt-nodejs14/root/usr/lib/node_modules/npm/node_modules.bundled/stream-iterate/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //opt/alt/alt-nodejs14/root/usr/lib/node_modules/npm/node_modules.bundled/stream-iterate/index.js

var Readable = require('readable-stream').Readable
var shift = require('stream-shift')

var stream2 = function (stream) {
  if (stream._readableState) return stream
  return new Readable({objectMode: true, highWaterMark: 16}).wrap(stream)
}

module.exports = function (stream) {
  stream = stream2(stream)

  var ended = false
  var data = null
  var err = null
  var destroyed = false
  var fn = null

  var consume = function (e) {
    if (e) {
      destroyed = true
      if (stream.destroy) stream.destroy(e)
      return
    }

    data = null
    err = null
  }

  var onresult = function () {
    if (!fn) return
    var tmp = fn
    fn = undefined
    tmp(err, data, consume)
  }

  var update = function () {
    if (!fn) return
    data = shift(stream)
    if (data === null && !ended) return
    onresult()
  }

  var onend = function () {
    ended = true
    onresult()
  }

  stream.on('readable', update)

  stream.on('error', function (e) {
    err = e
    onresult()
  })

  stream.on('close', function () {
    if (stream._readableState.ended) return
    onend()
  })

  stream.on('end', onend)

  return function (callback) {
    if (destroyed) return
    if (err) return callback(err, null, consume)
    if (data) return callback(null, data, consume)
    if (ended) return callback(null, null, consume)
    fn = callback
    update()
  }
}