zip-lib 1.1.0 → 1.1.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.
@@ -168,54 +168,6 @@ async function mkdir(folder) {
168
168
  throw error; // rethrow original error
169
169
  }
170
170
  }
171
- // // Any other error: check if folder exists and
172
- // // return normally in that case if its a folder
173
- // try {
174
- // if (folder.includes("dirlink")) {
175
- // console.log("tttttt11111", folder);
176
- // }
177
- // const fileStat = await fs.lstat(folder);
178
- // if (folder.includes("dirlink")) {
179
- // console.log("tttttt22222", fileStat);
180
- // }
181
- // if (fileStat.isSymbolicLink()) {
182
- // console.log("kkkkkkkkk", fileStat);
183
- // const realFilePath = await realpath(folder);
184
- // const realFileStat = await fs.lstat(realFilePath);
185
- // if (!realFileStat.isDirectory()) {
186
- // return Promise.reject(new Error(`"${folder}" exists and is not a directory.`));
187
- // }
188
- // return {
189
- // isDirectory: false,
190
- // isSymbolicLink: true,
191
- // realpath: realFilePath,
192
- // }
193
- // } else {
194
- // if (!fileStat.isDirectory()) {
195
- // return Promise.reject(new Error(`"${folder}" exists and is not a directory.`));
196
- // }
197
- // return {
198
- // isDirectory: true,
199
- // isSymbolicLink: false,
200
- // }
201
- // }
202
- // } catch (statError) {
203
- // if (folder.includes("dirlink")) {
204
- // console.log("yyyyy", statError);
205
- // }
206
- // // ignore
207
- // }
208
- // if (folder.includes("dirlink")) {
209
- // console.log("kkkkkkkkk22222", folder);
210
- // }
211
- // await fs.mkdir(folder, { recursive: true, mode: 0o777 });
212
- // if (folder.includes("dirlink")) {
213
- // console.log("kkkkkkkkk3333333", folder);
214
- // }
215
- // return {
216
- // isDirectory: true,
217
- // isSymbolicLink: false,
218
- // };
219
171
  }
220
172
  // "A"
221
173
  const charA = 65;
@@ -41,6 +41,7 @@ class EntryContext {
41
41
  this.symlinkAsFileOnWindows = symlinkAsFileOnWindows;
42
42
  this._symlinkFileNames = [];
43
43
  this._symlinkFolders = [];
44
+ this._ensuredFolders = [];
44
45
  }
45
46
  get decodeEntryFileName() {
46
47
  return this._decodeEntryFileName;
@@ -57,29 +58,42 @@ class EntryContext {
57
58
  get symlinkFileNames() {
58
59
  return this._symlinkFileNames;
59
60
  }
60
- get symlinkFolders() {
61
- return this._symlinkFolders;
61
+ addSymlinkFolder(folder, realpath) {
62
+ const find = this._symlinkFolders.find((item) => item.folder === folder);
63
+ if (!find) {
64
+ this._symlinkFolders.push({ folder, realpath });
65
+ }
62
66
  }
63
67
  getFilePath() {
64
68
  return path.join(this.targetFolder, this.decodeEntryFileName);
65
69
  }
70
+ async ensureFolder(folder) {
71
+ if (this._ensuredFolders.includes(folder)) {
72
+ return;
73
+ }
74
+ const folderStat = await exfs.ensureFolder(folder);
75
+ if (folderStat.isSymbolicLink) {
76
+ this.addSymlinkFolder(folder, folderStat.realpath);
77
+ }
78
+ this._ensuredFolders.push(folder);
79
+ }
66
80
  async isOutsideTargetFolder(tpath) {
67
- if (this.symlinkFileNames.length === 0 &&
68
- this.symlinkFolders.length === 0) {
81
+ if (this._symlinkFileNames.length === 0 &&
82
+ this._symlinkFolders.length === 0) {
69
83
  return false;
70
84
  }
71
85
  if (process.platform === "win32" &&
72
86
  this.symlinkAsFileOnWindows) {
73
87
  return false;
74
88
  }
75
- for (const { folder, realpath } of this.symlinkFolders) {
89
+ for (const { folder, realpath } of this._symlinkFolders) {
76
90
  if (tpath.includes(folder)) {
77
91
  if (realpath.indexOf(this.realTargetFolder) !== 0) {
78
92
  return true;
79
93
  }
80
94
  }
81
95
  }
82
- for (const fileName of this.symlinkFileNames) {
96
+ for (const fileName of this._symlinkFileNames) {
83
97
  if (tpath.includes(fileName)) {
84
98
  const realFilePath = await exfs.realpath(tpath);
85
99
  if (realFilePath.indexOf(this.realTargetFolder) !== 0) {
@@ -252,13 +266,7 @@ class Unzip extends cancelable_1.Cancelable {
252
266
  async extractEntry(zfile, entry, entryContext, token) {
253
267
  const filePath = entryContext.getFilePath();
254
268
  const fileDir = path.dirname(filePath);
255
- const folderStat = await exfs.ensureFolder(fileDir);
256
- if (folderStat.isSymbolicLink) {
257
- entryContext.symlinkFolders.push({
258
- folder: fileDir,
259
- realpath: folderStat.realpath,
260
- });
261
- }
269
+ await entryContext.ensureFolder(fileDir);
262
270
  const outside = await entryContext.isOutsideTargetFolder(fileDir);
263
271
  if (outside) {
264
272
  const error = new Error(`Refuse to write file outside "${entryContext.targetFolder}", file: "${filePath}"`);
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "zip-lib",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "zip and unzip library for node",
5
5
  "main": "lib/index.js",
6
+ "types": "./lib/index.d.ts",
6
7
  "scripts": {
7
8
  "compile": "rimraf ./dist && tsc -p ./src/tsconfig.json",
8
- "release": "rimraf ./lib && tsc -p ./src/tsconfig.release.json && node ./build.mjs",
9
+ "release": "rimraf ./pkg && npm run tsc-cjs && node ./build.mjs",
10
+ "tsc-cjs": "tsc -p ./src/tsconfig.production.cjs.json",
9
11
  "compile-test": "rimraf ./test/out && tsc -p ./test/src/tsconfig.json",
10
12
  "test": "npm run compile && npm run compile-test && node ./test/src/before.js && mocha ./test/out --timeout 10000"
11
13
  },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes