{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/fast-extract/src/streams/write/entries.mjs"],"sourcesContent":["import fs from 'fs';\nimport writer from 'flush-write-stream';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport tempSuffix from 'temp-suffix';\n\nexport default function createWriteEntriesStream(dest, options = {}) {\n  options = { now: new Date(), ...options };\n\n  const tempDest = tempSuffix(dest);\n  const links = [];\n  return writer(\n    { objectMode: true },\n    function write(entry, _encoding, callback) {\n      if (entry.type === 'link') {\n        links.unshift(entry);\n        return callback();\n      }\n      if (entry.type === 'symlink') {\n        links.push(entry);\n        return callback();\n      }\n      entry.create(tempDest, options, callback);\n    },\n    function flush(callback) {\n      const queue = new Queue(1);\n      queue.defer(rimraf2.bind(null, dest, { disableGlob: true }));\n      queue.defer(fs.rename.bind(fs, tempDest, dest));\n      let entry;\n      for (let index = 0; index < links.length; index++) {\n        entry = links[index];\n        queue.defer(entry.create.bind(entry, dest, options));\n      }\n      queue.await(callback);\n    }\n  );\n}\n"],"names":["fs","writer","Queue","rimraf2","tempSuffix","createWriteEntriesStream","dest","options","now","Date","tempDest","links","objectMode","write","entry","_encoding","callback","type","unshift","push","create","flush","queue","defer","bind","disableGlob","rename","index","length","await"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,YAAY,qBAAqB;AACxC,OAAOC,WAAW,WAAW;AAC7B,OAAOC,aAAa,UAAU;AAE9B,OAAOC,gBAAgB,cAAc;AAErC,eAAe,SAASC,yBAAyBC,IAAI,EAAEC,UAAU,CAAC,CAAC;IACjEA,UAAU;QAAEC,KAAK,IAAIC;QAAQ,GAAGF,OAAO;IAAC;IAExC,MAAMG,WAAWN,WAAWE;IAC5B,MAAMK,QAAQ,EAAE;IAChB,OAAOV,OACL;QAAEW,YAAY;IAAK,GACnB,SAASC,MAAMC,KAAK,EAAEC,SAAS,EAAEC,QAAQ;QACvC,IAAIF,MAAMG,IAAI,KAAK,QAAQ;YACzBN,MAAMO,OAAO,CAACJ;YACd,OAAOE;QACT;QACA,IAAIF,MAAMG,IAAI,KAAK,WAAW;YAC5BN,MAAMQ,IAAI,CAACL;YACX,OAAOE;QACT;QACAF,MAAMM,MAAM,CAACV,UAAUH,SAASS;IAClC,GACA,SAASK,MAAML,QAAQ;QACrB,MAAMM,QAAQ,IAAIpB,MAAM;QACxBoB,MAAMC,KAAK,CAACpB,QAAQqB,IAAI,CAAC,MAAMlB,MAAM;YAAEmB,aAAa;QAAK;QACzDH,MAAMC,KAAK,CAACvB,GAAG0B,MAAM,CAACF,IAAI,CAACxB,IAAIU,UAAUJ;QACzC,IAAIQ;QACJ,IAAK,IAAIa,QAAQ,GAAGA,QAAQhB,MAAMiB,MAAM,EAAED,QAAS;YACjDb,QAAQH,KAAK,CAACgB,MAAM;YACpBL,MAAMC,KAAK,CAACT,MAAMM,MAAM,CAACI,IAAI,CAACV,OAAOR,MAAMC;QAC7C;QACAe,MAAMO,KAAK,CAACb;IACd;AAEJ"}