@tmlmobilidade/go-utils-zip 20261024.1516.10 → 20261026.1111.43

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.
@@ -18,14 +18,15 @@ export async function getZipFileHash(filePath) {
18
18
  //
19
19
  // Initialize a new temporary directory
20
20
  const temporaryDirectory = fs.mkdtempDisposableSync('get-zip-file-hash-');
21
+ const extractedDirectoryPath = path.join(temporaryDirectory.path, 'extracted');
21
22
  try {
22
23
  //
23
24
  //
24
25
  // Extract the ZIP file into the temporary directory.
25
- await unzipFile(filePath, temporaryDirectory.path);
26
+ await unzipFile(filePath, extractedDirectoryPath);
26
27
  //
27
28
  // Find all extracted files.
28
- const sortedExtractedFilePaths = getDirectoryFiles(temporaryDirectory.path);
29
+ const sortedExtractedFilePaths = getDirectoryFiles(extractedDirectoryPath);
29
30
  //
30
31
  // Initialize the list of files to hash.
31
32
  const foundFiles = [];
@@ -39,16 +40,13 @@ export async function getZipFileHash(filePath) {
39
40
  hash.update(chunk);
40
41
  }
41
42
  // Add the file to the list of files to hash.
42
- const relativeFilePath = path.relative(temporaryDirectory.path, absolutePath);
43
+ const relativeFilePath = path.relative(extractedDirectoryPath, absolutePath);
43
44
  foundFiles.push({ hash: hash.digest('hex'), path: relativeFilePath });
44
45
  }
45
46
  //
46
47
  // Make the result independent of the order of entries in the zip file.
47
48
  foundFiles.sort((a, b) => a.path.localeCompare(b.path));
48
49
  //
49
- // Clean up the temporary directory.
50
- temporaryDirectory.remove();
51
- //
52
50
  // Calculate the final hash by concatenating the sorted list
53
51
  // of filenames and individual file hashes.
54
52
  const finalHash = createHash('sha256');
@@ -36,6 +36,7 @@ export async function unzipFile(zipFilePath, outputDir, dirPermissionsMode = 0o6
36
36
  // file entry
37
37
  const readStream = await zipfile.openReadStreamPromise(entry);
38
38
  const filePath = path.join(outputDir, entry.fileName);
39
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
39
40
  await pipeline(readStream, fs.createWriteStream(filePath));
40
41
  }
41
42
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-utils-zip",
3
- "version": "20261024.1516.10",
3
+ "version": "20261026.1111.43",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"