How to use the readable-stream.finished function in readable-stream

To help you get started, we’ve selected a few readable-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fastify / fastify / lib / reply.js View on Github external
Reply.prototype.then = function (fullfilled, rejected) {
  if (this.sent) {
    fullfilled()
    return
  }

  eos(this.res, function (err) {
    // We must not treat ERR_STREAM_PREMATURE_CLOSE as
    // an error because it is created by eos, not by the stream.
    if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
      if (rejected) {
        rejected(err)
      }
    } else {
      fullfilled()
    }
  })
}
github fastify / fastify / lib / reply.js View on Github external
var sourceOpen = true

  eos(payload, { readable: true, writable: false }, function (err) {
    sourceOpen = false
    if (err != null) {
      if (res.headersSent) {
        reply.log.warn({ err }, 'response terminated with an error with headers already sent')
        res.destroy()
      } else {
        onErrorHook(reply, err)
      }
    }
    // there is nothing to do if there is not an error
  })

  eos(res, function (err) {
    if (err != null) {
      if (res.headersSent) {
        reply.log.warn({ err }, 'response terminated with an error with headers already sent')
      }
      if (sourceOpen) {
        if (payload.destroy) {
          payload.destroy()
        } else if (typeof payload.close === 'function') {
          payload.close(noop)
        } else if (typeof payload.abort === 'function') {
          payload.abort()
        }
      }
    }
  })
github fastify / fastify / lib / reply.js View on Github external
function sendStream (payload, res, reply) {
  var sourceOpen = true

  eos(payload, { readable: true, writable: false }, function (err) {
    sourceOpen = false
    if (err != null) {
      if (res.headersSent) {
        reply.log.warn({ err }, 'response terminated with an error with headers already sent')
        res.destroy()
      } else {
        onErrorHook(reply, err)
      }
    }
    // there is nothing to do if there is not an error
  })

  eos(res, function (err) {
    if (err != null) {
      if (res.headersSent) {
        reply.log.warn({ err }, 'response terminated with an error with headers already sent')
github ravendb / ravendb-nodejs-client / test / Documents / ReadmeSamples.ts View on Github external
await new Promise((resolve, reject) => {
                stream.finished(userStream, err => {
                    err ? reject(err) : resolve();
                });
            });
        });
github aws / aws-encryption-sdk-javascript / modules / decrypt-node / src / decrypt.ts View on Github external
return new Promise((resolve, reject) => {
    finished(stream, (err: Error) => err ? reject(err) : resolve())
  })
}
github aws / aws-encryption-sdk-javascript / modules / encrypt-node / src / encrypt.ts View on Github external
return new Promise((resolve, reject) => {
    finished(stream, (err: Error) => err ? reject(err) : resolve())
  })
}