extract-base-iterator 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/FileEntry.js +2 -0
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/waitForAccess.d.cts +1 -1
- package/dist/cjs/waitForAccess.d.ts +1 -1
- package/dist/cjs/waitForAccess.js +2 -1
- package/dist/cjs/waitForAccess.js.map +1 -1
- package/dist/esm/FileEntry.js +2 -0
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/waitForAccess.d.ts +1 -1
- package/dist/esm/waitForAccess.js +2 -1
- package/dist/esm/waitForAccess.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/FileEntry.js
CHANGED
|
@@ -19,6 +19,7 @@ var _utimests = /*#__PURE__*/ _interop_require_default(require("./fs/utimes.js")
|
|
|
19
19
|
var _indexts = require("./shared/index.js");
|
|
20
20
|
var _stripPathts = /*#__PURE__*/ _interop_require_default(require("./stripPath.js"));
|
|
21
21
|
var _validateAttributests = /*#__PURE__*/ _interop_require_default(require("./validateAttributes.js"));
|
|
22
|
+
var _waitForAccessts = /*#__PURE__*/ _interop_require_default(require("./waitForAccess.js"));
|
|
22
23
|
function _class_call_check(instance, Constructor) {
|
|
23
24
|
if (!(instance instanceof Constructor)) {
|
|
24
25
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -82,6 +83,7 @@ var FileEntry = /*#__PURE__*/ function() {
|
|
|
82
83
|
}
|
|
83
84
|
queue.defer(_mkdirpclassic.default.bind(null, _path.default.dirname(fullPath)));
|
|
84
85
|
queue.defer(this._writeFile.bind(this, fullPath, options));
|
|
86
|
+
queue.defer(_waitForAccessts.default.bind(null, fullPath));
|
|
85
87
|
queue.defer(_chmodts.default.bind(null, fullPath, this, options));
|
|
86
88
|
queue.defer(_chownts.default.bind(null, fullPath, this, options));
|
|
87
89
|
queue.defer(_utimests.default.bind(null, fullPath, this, options));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n\n if (typeof callback === 'function') {\n options = options || {};\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = path.join(dest, stripPath(normalizedPath, options as ExtractOptions));\n\n const queue = new Queue(1);\n if ((options as ExtractOptions).force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n } else {\n // Check if file exists - throw EEXIST if it does\n queue.defer((callback) => {\n fs.stat(fullPath, (err) => {\n if (!err) {\n const existsErr = new Error(`EEXIST: file already exists, open '${fullPath}'`) as NodeJS.ErrnoException;\n existsErr.code = 'EEXIST';\n existsErr.path = fullPath;\n return callback(existsErr);\n }\n // ENOENT means file doesn't exist - that's what we want\n if (err.code === 'ENOENT') return callback();\n // Other errors should be reported\n callback(err);\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer((this as unknown as AbstractFileEntry)._writeFile.bind(this, fullPath, options));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n return;\n } catch (err) {\n callback(err);\n return;\n }\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options as ExtractOptions, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n destroy() {}\n}\n"],"names":["FileEntry","MANDATORY_ATTRIBUTES","attributes","validateAttributes","objectAssign","basename","undefined","path","type","_writeFile","Error","create","dest","options","callback","normalizedPath","normalize","fullPath","join","stripPath","queue","Queue","force","defer","rm","err","code","fs","stat","existsErr","mkdirp","bind","dirname","chmod","chown","utimes","await","Promise","resolve","reject","done","destroy"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n\n if (typeof callback === 'function') {\n options = options || {};\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = path.join(dest, stripPath(normalizedPath, options as ExtractOptions));\n\n const queue = new Queue(1);\n if ((options as ExtractOptions).force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n } else {\n // Check if file exists - throw EEXIST if it does\n queue.defer((callback) => {\n fs.stat(fullPath, (err) => {\n if (!err) {\n const existsErr = new Error(`EEXIST: file already exists, open '${fullPath}'`) as NodeJS.ErrnoException;\n existsErr.code = 'EEXIST';\n existsErr.path = fullPath;\n return callback(existsErr);\n }\n // ENOENT means file doesn't exist - that's what we want\n if (err.code === 'ENOENT') return callback();\n // Other errors should be reported\n callback(err);\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer((this as unknown as AbstractFileEntry)._writeFile.bind(this, fullPath, options));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n return;\n } catch (err) {\n callback(err);\n return;\n }\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options as ExtractOptions, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n destroy() {}\n}\n"],"names":["FileEntry","MANDATORY_ATTRIBUTES","attributes","validateAttributes","objectAssign","basename","undefined","path","type","_writeFile","Error","create","dest","options","callback","normalizedPath","normalize","fullPath","join","stripPath","queue","Queue","force","defer","rm","err","code","fs","stat","existsErr","mkdirp","bind","dirname","waitForAccess","chmod","chown","utimes","await","Promise","resolve","reject","done","destroy"],"mappings":";;;;;;;eAsBqBA;;;yDAtBN;8BACI;oEACA;2DACF;8DACC;8DACA;8DACA;+DACC;uBACU;kEACP;2EACS;sEACL;;;;;;;;;;;AAE1B,IAAMC,uBAAuB;IAAC;IAAQ;IAAS;CAAO;AASvC,IAAA,AAAMD,0BAAN;;aAAMA,UAOPE,UAA0B;gCAPnBF;QAQjBG,IAAAA,6BAAkB,EAACD,YAAYD;QAC/BG,IAAAA,qBAAY,EAAC,IAAI,EAAEF;QACnB,IAAI,IAAI,CAACG,QAAQ,KAAKC,WAAW,IAAI,CAACD,QAAQ,GAAGE,aAAI,CAACF,QAAQ,CAAC,IAAI,CAACE,IAAI;QACxE,IAAI,IAAI,CAACC,IAAI,KAAKF,WAAW,IAAI,CAACE,IAAI,GAAG;QACzC,IAAI,AAAC,IAAI,CAAkCC,UAAU,KAAKH,WAAW,MAAM,IAAII,MAAM;;iBAZpEV;IAkBnBW,OAAAA,MAqDC,GArDDA,SAAAA,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B;;QACzF,IAAI,OAAOD,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QAEA,IAAI,OAAOC,aAAa,YAAY;YAClCD,UAAUA,WAAW,CAAC;YACtB,IAAI;gBACF,IAAME,iBAAiBR,aAAI,CAACS,SAAS,CAAC,IAAI,CAACT,IAAI;gBAC/C,IAAMU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K;gBACZX,SAASW;gBACT;YACF;QACF;QAEA,OAAO,IAAIa,QAAQ,SAACC,SAASC;YAC3B,MAAK7B,MAAM,CAACC,MAAMC,SAA2B,SAACY,KAAagB;uBAAoBhB,MAAMe,OAAOf,OAAOc,QAAQE;;QAC7G;IACF;IAEAC,OAAAA,OAAY,GAAZA,SAAAA,WAAW;WAzEQ1C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NoParamCallback } from './types.js';
|
|
2
|
-
export default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts?: number):
|
|
2
|
+
export default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts?: number): NodeJS.Timeout;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NoParamCallback } from './types.js';
|
|
2
|
-
export default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts?: number):
|
|
2
|
+
export default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts?: number): NodeJS.Timeout;
|
|
@@ -32,7 +32,8 @@ function waitForAccess(fullPath, noFollowOrCallback, callbackOrAttempts) {
|
|
|
32
32
|
callback = callbackOrAttempts;
|
|
33
33
|
}
|
|
34
34
|
// POSIX: finish event is reliable after decompression stream fixes
|
|
35
|
-
|
|
35
|
+
// Use setTimeout(0) to maintain async consistency (avoid Zalgo)
|
|
36
|
+
if (!isWindows) return setTimeout(callback, 0);
|
|
36
37
|
// Windows: NTFS metadata may not be committed yet, verify accessibility
|
|
37
38
|
// For symlinks (noFollow=true), use lstat to check the link itself exists
|
|
38
39
|
// For files/dirs/hardlinks, use open to verify the file is accessible
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/waitForAccess.ts"],"sourcesContent":["import fs from 'fs';\n\nimport type { NoParamCallback } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n// Backward compatible: waitForAccess(path, callback) or waitForAccess(path, noFollow, callback)\nexport default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts = 0) {\n // Parse arguments for backward compatibility\n let noFollow: boolean;\n let callback: NoParamCallback;\n if (typeof noFollowOrCallback === 'function') {\n // Old signature: waitForAccess(path, callback, attempts?)\n noFollow = false;\n callback = noFollowOrCallback;\n attempts = (callbackOrAttempts as number) || 0;\n } else {\n // New signature: waitForAccess(path, noFollow, callback, attempts?)\n noFollow = noFollowOrCallback;\n callback = callbackOrAttempts as NoParamCallback;\n }\n\n // POSIX: finish event is reliable after decompression stream fixes\n if (!isWindows) return callback
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/waitForAccess.ts"],"sourcesContent":["import fs from 'fs';\n\nimport type { NoParamCallback } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n// Backward compatible: waitForAccess(path, callback) or waitForAccess(path, noFollow, callback)\nexport default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts = 0) {\n // Parse arguments for backward compatibility\n let noFollow: boolean;\n let callback: NoParamCallback;\n if (typeof noFollowOrCallback === 'function') {\n // Old signature: waitForAccess(path, callback, attempts?)\n noFollow = false;\n callback = noFollowOrCallback;\n attempts = (callbackOrAttempts as number) || 0;\n } else {\n // New signature: waitForAccess(path, noFollow, callback, attempts?)\n noFollow = noFollowOrCallback;\n callback = callbackOrAttempts as NoParamCallback;\n }\n\n // POSIX: finish event is reliable after decompression stream fixes\n // Use setTimeout(0) to maintain async consistency (avoid Zalgo)\n if (!isWindows) return setTimeout(callback, 0);\n\n // Windows: NTFS metadata may not be committed yet, verify accessibility\n // For symlinks (noFollow=true), use lstat to check the link itself exists\n // For files/dirs/hardlinks, use open to verify the file is accessible\n if (noFollow) {\n fs.lstat(fullPath, (err) => {\n if (err) {\n if (err.code === 'ENOENT' && attempts < 10) {\n const delay = Math.min(5 * 2 ** attempts, 2560);\n return setTimeout(() => waitForAccess(fullPath, noFollow, callback, attempts + 1), delay);\n }\n return callback(err);\n }\n callback();\n });\n } else {\n fs.open(fullPath, 'r', (err, fd) => {\n if (err) {\n if (err.code === 'ENOENT' && attempts < 10) {\n // Exponential backoff: 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560ms\n // Total max wait: ~5 seconds\n const delay = Math.min(5 * 2 ** attempts, 2560);\n return setTimeout(() => waitForAccess(fullPath, noFollow, callback, attempts + 1), delay);\n }\n return callback(err);\n }\n fs.close(fd, () => callback());\n });\n }\n}\n"],"names":["waitForAccess","isWindows","process","platform","test","env","OSTYPE","fullPath","noFollowOrCallback","callbackOrAttempts","attempts","noFollow","callback","setTimeout","fs","lstat","err","code","delay","Math","min","open","fd","close"],"mappings":";;;;+BAMA,gGAAgG;AAChG;;;eAAwBA;;;yDAPT;;;;;;AAIf,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAG5E,SAASN,cAAcO,QAAgB,EAAEC,kBAA6C,EAAEC,kBAA6C;QAAEC,WAAAA,iEAAW;IAC/J,6CAA6C;IAC7C,IAAIC;IACJ,IAAIC;IACJ,IAAI,OAAOJ,uBAAuB,YAAY;QAC5C,0DAA0D;QAC1DG,WAAW;QACXC,WAAWJ;QACXE,WAAW,AAACD,sBAAiC;IAC/C,OAAO;QACL,oEAAoE;QACpEE,WAAWH;QACXI,WAAWH;IACb;IAEA,mEAAmE;IACnE,gEAAgE;IAChE,IAAI,CAACR,WAAW,OAAOY,WAAWD,UAAU;IAE5C,wEAAwE;IACxE,0EAA0E;IAC1E,sEAAsE;IACtE,IAAID,UAAU;QACZG,WAAE,CAACC,KAAK,CAACR,UAAU,SAACS;YAClB,IAAIA,KAAK;gBACP,IAAIA,IAAIC,IAAI,KAAK,YAAYP,WAAW,IAAI;oBAC1C,IAAMQ,QAAQC,KAAKC,GAAG,CAAC,aAAI,GAAKV,WAAU;oBAC1C,OAAOG,WAAW;+BAAMb,cAAcO,UAAUI,UAAUC,UAAUF,WAAW;uBAAIQ;gBACrF;gBACA,OAAON,SAASI;YAClB;YACAJ;QACF;IACF,OAAO;QACLE,WAAE,CAACO,IAAI,CAACd,UAAU,KAAK,SAACS,KAAKM;YAC3B,IAAIN,KAAK;gBACP,IAAIA,IAAIC,IAAI,KAAK,YAAYP,WAAW,IAAI;oBAC1C,sEAAsE;oBACtE,6BAA6B;oBAC7B,IAAMQ,QAAQC,KAAKC,GAAG,CAAC,aAAI,GAAKV,WAAU;oBAC1C,OAAOG,WAAW;+BAAMb,cAAcO,UAAUI,UAAUC,UAAUF,WAAW;uBAAIQ;gBACrF;gBACA,OAAON,SAASI;YAClB;YACAF,WAAE,CAACS,KAAK,CAACD,IAAI;uBAAMV;;QACrB;IACF;AACF"}
|
package/dist/esm/FileEntry.js
CHANGED
|
@@ -9,6 +9,7 @@ import utimes from './fs/utimes.js';
|
|
|
9
9
|
import { objectAssign } from './shared/index.js';
|
|
10
10
|
import stripPath from './stripPath.js';
|
|
11
11
|
import validateAttributes from './validateAttributes.js';
|
|
12
|
+
import waitForAccess from './waitForAccess.js';
|
|
12
13
|
const MANDATORY_ATTRIBUTES = [
|
|
13
14
|
'mode',
|
|
14
15
|
'mtime',
|
|
@@ -51,6 +52,7 @@ let FileEntry = class FileEntry {
|
|
|
51
52
|
}
|
|
52
53
|
queue.defer(mkdirp.bind(null, path.dirname(fullPath)));
|
|
53
54
|
queue.defer(this._writeFile.bind(this, fullPath, options));
|
|
55
|
+
queue.defer(waitForAccess.bind(null, fullPath));
|
|
54
56
|
queue.defer(chmod.bind(null, fullPath, this, options));
|
|
55
57
|
queue.defer(chown.bind(null, fullPath, this, options));
|
|
56
58
|
queue.defer(utimes.bind(null, fullPath, this, options));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n\n if (typeof callback === 'function') {\n options = options || {};\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = path.join(dest, stripPath(normalizedPath, options as ExtractOptions));\n\n const queue = new Queue(1);\n if ((options as ExtractOptions).force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n } else {\n // Check if file exists - throw EEXIST if it does\n queue.defer((callback) => {\n fs.stat(fullPath, (err) => {\n if (!err) {\n const existsErr = new Error(`EEXIST: file already exists, open '${fullPath}'`) as NodeJS.ErrnoException;\n existsErr.code = 'EEXIST';\n existsErr.path = fullPath;\n return callback(existsErr);\n }\n // ENOENT means file doesn't exist - that's what we want\n if (err.code === 'ENOENT') return callback();\n // Other errors should be reported\n callback(err);\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer((this as unknown as AbstractFileEntry)._writeFile.bind(this, fullPath, options));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n return;\n } catch (err) {\n callback(err);\n return;\n }\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options as ExtractOptions, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n destroy() {}\n}\n"],"names":["fs","rm","mkdirp","path","Queue","chmod","chown","utimes","objectAssign","stripPath","validateAttributes","MANDATORY_ATTRIBUTES","FileEntry","create","dest","options","callback","normalizedPath","normalize","fullPath","join","queue","force","defer","err","code","stat","existsErr","Error","bind","dirname","_writeFile","await","Promise","resolve","reject","done","destroy","attributes","basename","undefined","type"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,SAASC,EAAE,QAAQ,mBAAmB;AACtC,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,YAAY,iBAAiB;AACpC,SAASC,YAAY,QAAQ,oBAAoB;AACjD,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,wBAAwB,0BAA0B;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n\n if (typeof callback === 'function') {\n options = options || {};\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = path.join(dest, stripPath(normalizedPath, options as ExtractOptions));\n\n const queue = new Queue(1);\n if ((options as ExtractOptions).force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n } else {\n // Check if file exists - throw EEXIST if it does\n queue.defer((callback) => {\n fs.stat(fullPath, (err) => {\n if (!err) {\n const existsErr = new Error(`EEXIST: file already exists, open '${fullPath}'`) as NodeJS.ErrnoException;\n existsErr.code = 'EEXIST';\n existsErr.path = fullPath;\n return callback(existsErr);\n }\n // ENOENT means file doesn't exist - that's what we want\n if (err.code === 'ENOENT') return callback();\n // Other errors should be reported\n callback(err);\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer((this as unknown as AbstractFileEntry)._writeFile.bind(this, fullPath, options));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n return;\n } catch (err) {\n callback(err);\n return;\n }\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options as ExtractOptions, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n destroy() {}\n}\n"],"names":["fs","rm","mkdirp","path","Queue","chmod","chown","utimes","objectAssign","stripPath","validateAttributes","waitForAccess","MANDATORY_ATTRIBUTES","FileEntry","create","dest","options","callback","normalizedPath","normalize","fullPath","join","queue","force","defer","err","code","stat","existsErr","Error","bind","dirname","_writeFile","await","Promise","resolve","reject","done","destroy","attributes","basename","undefined","type"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,SAASC,EAAE,QAAQ,mBAAmB;AACtC,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,YAAY,iBAAiB;AACpC,SAASC,YAAY,QAAQ,oBAAoB;AACjD,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,wBAAwB,0BAA0B;AACzD,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,uBAAuB;IAAC;IAAQ;IAAS;CAAO;AASvC,IAAA,AAAMC,YAAN,MAAMA;IAkBnBC,OAAOC,IAAY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B,MAAMwB,IAAI,CAAC,MAAMV,UAAU,IAAI,EAAEJ;gBAC7CM,MAAME,KAAK,CAACjB,OAAOuB,IAAI,CAAC,MAAMV,UAAU,IAAI,EAAEJ;gBAC9CM,MAAMW,KAAK,CAAChB;gBACZ;YACF,EAAE,OAAOQ,KAAK;gBACZR,SAASQ;gBACT;YACF;QACF;QAEA,OAAO,IAAIS,QAAQ,CAACC,SAASC;YAC3B,IAAI,CAACtB,MAAM,CAACC,MAAMC,SAA2B,CAACS,KAAaY,OAAoBZ,MAAMW,OAAOX,OAAOU,QAAQE;QAC7G;IACF;IAEAC,UAAU,CAAC;IAlEX,YAAYC,UAA0B,CAAE;QACtC7B,mBAAmB6B,YAAY3B;QAC/BJ,aAAa,IAAI,EAAE+B;QACnB,IAAI,IAAI,CAACC,QAAQ,KAAKC,WAAW,IAAI,CAACD,QAAQ,GAAGrC,KAAKqC,QAAQ,CAAC,IAAI,CAACrC,IAAI;QACxE,IAAI,IAAI,CAACuC,IAAI,KAAKD,WAAW,IAAI,CAACC,IAAI,GAAG;QACzC,IAAI,AAAC,IAAI,CAAkCV,UAAU,KAAKS,WAAW,MAAM,IAAIZ,MAAM;IACvF;AA6DF;AA1EA,SAAqBhB,uBA0EpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NoParamCallback } from './types.js';
|
|
2
|
-
export default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts?: number):
|
|
2
|
+
export default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts?: number): NodeJS.Timeout;
|
|
@@ -16,7 +16,8 @@ export default function waitForAccess(fullPath, noFollowOrCallback, callbackOrAt
|
|
|
16
16
|
callback = callbackOrAttempts;
|
|
17
17
|
}
|
|
18
18
|
// POSIX: finish event is reliable after decompression stream fixes
|
|
19
|
-
|
|
19
|
+
// Use setTimeout(0) to maintain async consistency (avoid Zalgo)
|
|
20
|
+
if (!isWindows) return setTimeout(callback, 0);
|
|
20
21
|
// Windows: NTFS metadata may not be committed yet, verify accessibility
|
|
21
22
|
// For symlinks (noFollow=true), use lstat to check the link itself exists
|
|
22
23
|
// For files/dirs/hardlinks, use open to verify the file is accessible
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/waitForAccess.ts"],"sourcesContent":["import fs from 'fs';\n\nimport type { NoParamCallback } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n// Backward compatible: waitForAccess(path, callback) or waitForAccess(path, noFollow, callback)\nexport default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts = 0) {\n // Parse arguments for backward compatibility\n let noFollow: boolean;\n let callback: NoParamCallback;\n if (typeof noFollowOrCallback === 'function') {\n // Old signature: waitForAccess(path, callback, attempts?)\n noFollow = false;\n callback = noFollowOrCallback;\n attempts = (callbackOrAttempts as number) || 0;\n } else {\n // New signature: waitForAccess(path, noFollow, callback, attempts?)\n noFollow = noFollowOrCallback;\n callback = callbackOrAttempts as NoParamCallback;\n }\n\n // POSIX: finish event is reliable after decompression stream fixes\n if (!isWindows) return callback
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/waitForAccess.ts"],"sourcesContent":["import fs from 'fs';\n\nimport type { NoParamCallback } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n// Backward compatible: waitForAccess(path, callback) or waitForAccess(path, noFollow, callback)\nexport default function waitForAccess(fullPath: string, noFollowOrCallback: boolean | NoParamCallback, callbackOrAttempts?: NoParamCallback | number, attempts = 0) {\n // Parse arguments for backward compatibility\n let noFollow: boolean;\n let callback: NoParamCallback;\n if (typeof noFollowOrCallback === 'function') {\n // Old signature: waitForAccess(path, callback, attempts?)\n noFollow = false;\n callback = noFollowOrCallback;\n attempts = (callbackOrAttempts as number) || 0;\n } else {\n // New signature: waitForAccess(path, noFollow, callback, attempts?)\n noFollow = noFollowOrCallback;\n callback = callbackOrAttempts as NoParamCallback;\n }\n\n // POSIX: finish event is reliable after decompression stream fixes\n // Use setTimeout(0) to maintain async consistency (avoid Zalgo)\n if (!isWindows) return setTimeout(callback, 0);\n\n // Windows: NTFS metadata may not be committed yet, verify accessibility\n // For symlinks (noFollow=true), use lstat to check the link itself exists\n // For files/dirs/hardlinks, use open to verify the file is accessible\n if (noFollow) {\n fs.lstat(fullPath, (err) => {\n if (err) {\n if (err.code === 'ENOENT' && attempts < 10) {\n const delay = Math.min(5 * 2 ** attempts, 2560);\n return setTimeout(() => waitForAccess(fullPath, noFollow, callback, attempts + 1), delay);\n }\n return callback(err);\n }\n callback();\n });\n } else {\n fs.open(fullPath, 'r', (err, fd) => {\n if (err) {\n if (err.code === 'ENOENT' && attempts < 10) {\n // Exponential backoff: 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560ms\n // Total max wait: ~5 seconds\n const delay = Math.min(5 * 2 ** attempts, 2560);\n return setTimeout(() => waitForAccess(fullPath, noFollow, callback, attempts + 1), delay);\n }\n return callback(err);\n }\n fs.close(fd, () => callback());\n });\n }\n}\n"],"names":["fs","isWindows","process","platform","test","env","OSTYPE","waitForAccess","fullPath","noFollowOrCallback","callbackOrAttempts","attempts","noFollow","callback","setTimeout","lstat","err","code","delay","Math","min","open","fd","close"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AAIpB,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,gGAAgG;AAChG,eAAe,SAASC,cAAcC,QAAgB,EAAEC,kBAA6C,EAAEC,kBAA6C,EAAEC,WAAW,CAAC;IAChK,6CAA6C;IAC7C,IAAIC;IACJ,IAAIC;IACJ,I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