How to use the minipass.isStream function in minipass

To help you get started, we’ve selected a few minipass 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 npm / npm-registry-fetch / index.js View on Github external
uri = `${
      registry.trim().replace(/\/?$/g, '')
    }/${
      uri.trim().replace(/^\//, '')
    }`
  }

  const method = opts.method ||
    /* istanbul ignore next: default set in figgy pudding config */
    'GET'

  // through that takes into account the scope, the prefix of `uri`, etc
  const startTime = Date.now()
  const headers = getHeaders(registry, uri, opts)
  let body = opts.body
  const bodyIsStream = Minipass.isStream(body)
  const bodyIsPromise = body &&
    typeof body === 'object' &&
    typeof body.then === 'function'

  if (body && !bodyIsStream && !bodyIsPromise && typeof body !== 'string' && !Buffer.isBuffer(body)) {
    headers['content-type'] = headers['content-type'] || 'application/json'
    body = JSON.stringify(body)
  } else if (body && !headers['content-type']) {
    headers['content-type'] = 'application/octet-stream'
  }

  if (opts.gzip) {
    headers['content-encoding'] = 'gzip'
    if (bodyIsStream) {
      const gz = new zlib.Gzip()
      body.on('error', /* istanbul ignore next: unlikely and hard to test */
github npm / make-fetch-happen / index.js View on Github external
.then((res) => {
          if (opts.integrity) {
            res = remoteFetchHandleIntegrity(res, opts.integrity)
          }

          res.headers.set('x-fetch-attempts', attemptNum)

          const isStream = Minipass.isStream(req.body)

          if (opts.cacheManager) {
            const isMethodGetHead = (
              req.method === 'GET' ||
              req.method === 'HEAD'
            )

            const isCachable = (
              opts.cache !== 'no-store' &&
              isMethodGetHead &&
              makePolicy(req, res).storable() &&
              res.status === 200 // No other statuses should be stored!
            )

            if (isCachable) {
              return opts.cacheManager.put(req, res, opts)
github npm / make-fetch-happen / test / fetch.js View on Github external
.then((res) => {
        t.equal(res.status, 200, 'successful status code')
        t.ok(Minipass.isStream(res.body), 'body is a stream')
        return res.buffer()
      })
      .then((buf) => {

minipass

minimal implementation of a PassThrough stream

ISC
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis

Popular minipass functions