PHP 8.2.30
Preview: tarball.js Size: 1.97 KB
//lib/node_modules/npm/node_modules/pacote/tarball.js

'use strict'

const BB = require('bluebird')

const fs = require('fs')
const getStream = require('get-stream')
const mkdirp = BB.promisify(require('mkdirp'))
const npa = require('npm-package-arg')
const optCheck = require('./lib/util/opt-check.js')
const PassThrough = require('stream').PassThrough
const path = require('path')
const rimraf = BB.promisify(require('rimraf'))
const withTarballStream = require('./lib/with-tarball-stream.js')

module.exports = tarball
function tarball (spec, opts) {
  opts = optCheck(opts)
  spec = npa(spec, opts.where)
  return withTarballStream(spec, opts, stream => getStream.buffer(stream))
}

module.exports.stream = tarballStream
function tarballStream (spec, opts) {
  opts = optCheck(opts)
  spec = npa(spec, opts.where)
  const output = new PassThrough()
  let hasTouchedOutput = false
  let lastError = null
  withTarballStream(spec, opts, stream => {
    if (hasTouchedOutput && lastError) {
      throw lastError
    } else if (hasTouchedOutput) {
      throw new Error('abort, abort!')
    } else {
      return new BB((resolve, reject) => {
        stream.on('error', reject)
        output.on('error', reject)
        output.on('error', () => { hasTouchedOutput = true })
        output.on('finish', resolve)
        stream.pipe(output)
        stream.once('data', () => { hasTouchedOutput = true })
      }).catch(err => {
        lastError = err
        throw err
      })
    }
  })
    .catch(err => output.emit('error', err))
  return output
}

module.exports.toFile = tarballToFile
function tarballToFile (spec, dest, opts) {
  opts = optCheck(opts)
  spec = npa(spec, opts.where)
  return mkdirp(path.dirname(dest))
    .then(() => withTarballStream(spec, opts, stream => {
      return rimraf(dest)
        .then(() => new BB((resolve, reject) => {
          const writer = fs.createWriteStream(dest)
          stream.on('error', reject)
          writer.on('error', reject)
          writer.on('close', resolve)
          stream.pipe(writer)
        }))
    }))
}

Directory Contents

Dirs: 2 × Files: 10

Name Size Perms Modified Actions
lib DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
43.39 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
2.99 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
262 B lrw-r--r-- 2021-03-10 14:36:37
Edit Download
1.08 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
1.12 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
3.35 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
822 B lrw-r--r-- 2021-03-10 14:36:37
Edit Download
1.93 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
9.60 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download
1.97 KB lrw-r--r-- 2021-03-10 14:36:37
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).