import{__exports as t}from"../../../../../_virtual/async5.mjs";import e from"../../../../../_virtual/_node_events.mjs";import{__require as r}from"../../../fs.scandir/out/index.mjs";import{__require as s}from"../../../../fastq/queue.mjs";import{__require as i}from"./common.mjs";import{__require as o}from"./reader.mjs";var n;function _(){if(n)return t;n=1,Object.defineProperty(t,"__esModule",{value:!0});const _=e,h=r(),a=s(),d=i(),u=o();class m extends u.default{constructor(t,e){super(t,e),this._settings=e,this._scandir=h.scandir,this._emitter=new _.EventEmitter,this._queue=a(this._worker.bind(this),this._settings.concurrency),this._isFatalError=!1,this._isDestroyed=!1,this._queue.drain=()=>{this._isFatalError||this._emitter.emit("end")}}read(){return this._isFatalError=!1,this._isDestroyed=!1,setImmediate(()=>{this._pushToQueue(this._root,this._settings.basePath)}),this._emitter}get isDestroyed(){return this._isDestroyed}destroy(){if(this._isDestroyed)throw new Error("The reader is already destroyed");this._isDestroyed=!0,this._queue.killAndDrain()}onEntry(t){this._emitter.on("entry",t)}onError(t){this._emitter.once("error",t)}onEnd(t){this._emitter.once("end",t)}_pushToQueue(t,e){const r={directory:t,base:e};this._queue.push(r,t=>{null!==t&&this._handleError(t)})}_worker(t,e){this._scandir(t.directory,this._settings.fsScandirSettings,(r,s)=>{if(null===r){for(const e of s)this._handleEntry(e,t.base);e(null,void 0)}else e(r,void 0)})}_handleError(t){!this._isDestroyed&&d.isFatalError(this._settings,t)&&(this._isFatalError=!0,this._isDestroyed=!0,this._emitter.emit("error",t))}_handleEntry(t,e){if(this._isDestroyed||this._isFatalError)return;const r=t.path;void 0!==e&&(t.path=d.joinPathSegments(e,t.name,this._settings.pathSegmentSeparator)),d.isAppliedFilter(this._settings.entryFilter,t)&&this._emitEntry(t),t.dirent.isDirectory()&&d.isAppliedFilter(this._settings.deepFilter,t)&&this._pushToQueue(r,void 0===e?void 0:t.path)}_emitEntry(t){this._emitter.emit("entry",t)}}return t.default=m,t}export{_ as __require};