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F,GACF,CACA,EAAU,KAAK,QAAS,GAExB,IAAI,EAAI,GACR,SAAS,IACP,GAAI,GAAK,EAAU,OAEjB,YADA,IAIF,MAAM,EAAW,EAAU,GAC3B,GAAK,EACL,MAAM,EAAe,EAAc,GACnC,GAAI,GAAgB,EAAkB,GAEpC,YADA,IAIF,MAAM,EAAW,GAAgB,GAAG,iBAAiB,GAOrD,SAAS,IACH,IACF,EAAkB,IAAY,GAEhC,IACA,GACF,CAEA,SAAS,EAAU,GAEjB,EAAI,SAAW,EACf,EAAa,cAAc,EAAY,GACvC,EAAU,MAAM,YAAY,MAAa,EAAI,aAGd,mBAApB,EAAS,QAClB,EAAS,OAAO,GAElB,GACF,CAxBA,EAAY,WACV,EAAS,eAAe,QAAS,GACjC,EAAS,eAAe,MAAO,EACjC,EAsBA,EAAS,KAAK,QAAS,GACvB,EAAS,KAAK,MAAO,GAErB,EAAS,KAAK,EAAW,CAAC,KAAK,GACjC,CAEA,EAEF,CAEA,OAAO,QAAU","file":"/npm/nodecat@2.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/nodecat@2.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @copyright Copyright 2016 Kevin Locke <kevin@kevinlocke.name>\n * @license MIT\n */\n\n'use strict';\n\nconst fs = require('fs');\n\nconst AggregateError = require('./lib/aggregate-error');\n\n/** Combines one or more errors into a single error.\n *\n * @param {AggregateError|Error} errPrev Previous errors, if any.\n * @param {!Error} errNew New error.\n * @return {!AggregateError|!Error} Error which represents all errors that have\n * occurred.  If only one error has occurred, it will be returned.  Otherwise\n * an {@link AggregateError} including all previous errors will be returned.\n * @private\n */\nfunction combineErrors(errPrev, errNew) {\n  if (!errPrev) {\n    return errNew;\n  }\n\n  let errCombined;\n  if (errPrev instanceof AggregateError) {\n    errCombined = errPrev;\n  } else {\n    errCombined = new AggregateError();\n    errCombined.push(errPrev);\n  }\n\n  errCombined.push(errNew);\n  return errCombined;\n}\n\n/** Options for {@link nodecat}.\n *\n * @typedef {{\n *   fileStreams: (Object<string,!stream.Readable>|undefined),\n *   outStream: (stream.Writable|undefined),\n *   errStream: (stream.Writable|undefined)\n * }} CommandOptions\n * @property {Object<string,!stream.Readable>=} fileStreams Mapping from file\n * names to readable streams which will be read for the named file.  If the\n * file appears multiple times, the stream is only read once.\n * @property {stream.Writable=} outStream Stream to which concatenated output\n * is written. (default: <code>process.stdout</code>)\n * @property {stream.Writable=} errStream Stream to which errors (and\n * non-output status messages) are written.\n * (default: <code>process.stderr</code>)\n */\n// var NodecatOptions;\n\n/** Concatenate named files.\n *\n * @param {!Array<string>} fileNames Names of files to be concatenated, in the\n * order in which their content will appear.  Files may appear multiple times.\n * If the Array is empty, no output will be written.\n * @param {NodecatOptions=} options Options.\n * @param {?function(Error)=} callback Callback with the first\n * <code>Error</code> which occurred, if any.  Note that concatenation\n * continues after errors.  Required if <code>global.Promise</code> is not\n * defined.\n * @return {Promise|undefined} If <code>callback</code> is not given and\n * <code>global.Promise</code> is defined, a <code>Promise</code> which\n * resolves once all output has been written.\n */\nfunction nodecat(fileNames, options, callback) {\n  if (!callback && typeof options === 'function') {\n    callback = options;\n    options = null;\n  }\n\n  if (!callback) {\n    return new Promise((resolve, reject) => {\n      nodecat(fileNames, options, (err, result) => {\n        if (err) { reject(err); } else { resolve(result); }\n      });\n    });\n  }\n\n  if (typeof callback !== 'function') {\n    throw new TypeError('callback must be a function');\n  }\n\n  const callerStreamEnded = {};\n  const callerStreams = (options && options.fileStreams) || {};\n  const errStream = (options && options.errStream) || process.stderr;\n  const outStream = (options && options.outStream) || process.stdout;\n\n  try {\n    if (!fileNames\n        || typeof fileNames !== 'object'\n        || fileNames.length !== Math.floor(fileNames.length)) {\n      throw new TypeError('fileNames must be an Array-like object');\n    }\n    if (options && typeof options !== 'object') {\n      throw new TypeError('options must be an object');\n    }\n    if (typeof callerStreams !== 'object') {\n      throw new TypeError('options.fileStreams must be an object');\n    }\n    if (typeof outStream.write !== 'function') {\n      throw new TypeError('options.outStream must be a stream.Writable');\n    }\n    if (typeof errStream.write !== 'function') {\n      throw new TypeError('options.errStream must be a stream.Writable');\n    }\n  } catch (err) {\n    process.nextTick(() => {\n      callback(err);\n    });\n    return undefined;\n  }\n\n  // Error which will be returned from nodecat\n  let errNodecat = null;\n  // Cleanup function for the currently piping input stream\n  let inCleanup;\n\n  function allDone() {\n    outStream.removeListener('error', onOutError);\n    callback(errNodecat);\n  }\n\n  // Note:  src.unpipe is called by stream.Readable internals on dest 'error'\n  function onOutError(err) {\n    errNodecat = combineErrors(errNodecat, err);\n    errStream.write(`nodecat: ${err}\\n`);\n    if (inCleanup) {\n      inCleanup();\n    }\n    allDone();\n  }\n  outStream.once('error', onOutError);\n\n  let i = 0;\n  function catNext() {\n    if (i >= fileNames.length) {\n      allDone();\n      return;\n    }\n\n    const fileName = fileNames[i];\n    i += 1;\n    const callerStream = callerStreams[fileName];\n    if (callerStream && callerStreamEnded[fileName]) {\n      catNext();\n      return;\n    }\n\n    const inStream = callerStream || fs.createReadStream(fileName);\n\n    inCleanup = function cleanup() {\n      inStream.removeListener('error', onInError);\n      inStream.removeListener('end', done);\n    };\n\n    function done() {\n      if (callerStream) {\n        callerStreamEnded[fileName] = true;\n      }\n      inCleanup();\n      catNext();\n    }\n\n    function onInError(err) {\n      // Mark error with the name of the file which caused it\n      err.fileName = fileName;\n      errNodecat = combineErrors(errNodecat, err);\n      errStream.write(`nodecat: ${fileName}: ${err.message}\\n`);\n      // There is no way to know whether more data may be emitted.\n      // To be safe, unpipe to prevent interleaving data after starting next.\n      if (typeof inStream.unpipe === 'function') {\n        inStream.unpipe(outStream);\n      }\n      done();\n    }\n    inStream.once('error', onInError);\n    inStream.once('end', done);\n\n    inStream.pipe(outStream, {end: false});\n  }\n\n  catNext();\n  return undefined;\n}\n\nmodule.exports = nodecat;\n"]}