@mcpher/gas-fakes 2.3.2 → 2.3.3
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/package.json +2 -6
- package/src/support/sxzip.js +18 -36
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
11
11
|
"@sindresorhus/is": "^7.2.0",
|
|
12
12
|
"acorn": "^8.16.0",
|
|
13
|
-
"
|
|
13
|
+
"adm-zip": "^0.5.16",
|
|
14
14
|
"commander": "^14.0.3",
|
|
15
15
|
"dotenv": "^17.3.1",
|
|
16
16
|
"fast-xml-parser": "^5.5.9",
|
|
@@ -24,12 +24,8 @@
|
|
|
24
24
|
"mime": "^4.1.0",
|
|
25
25
|
"prompts": "^2.4.2",
|
|
26
26
|
"sleep-synchronously": "^2.0.0",
|
|
27
|
-
"unzipper": "^0.12.3",
|
|
28
27
|
"zod": "^4.3.6"
|
|
29
28
|
},
|
|
30
|
-
"overrides": {
|
|
31
|
-
"minimatch": "^10.0.3"
|
|
32
|
-
},
|
|
33
29
|
"type": "module",
|
|
34
30
|
"scripts": {
|
|
35
31
|
"pub": "npm publish --access public",
|
|
@@ -39,7 +35,7 @@
|
|
|
39
35
|
},
|
|
40
36
|
"name": "@mcpher/gas-fakes",
|
|
41
37
|
"author": "bruce mcpherson",
|
|
42
|
-
"version": "2.3.
|
|
38
|
+
"version": "2.3.3",
|
|
43
39
|
"license": "MIT",
|
|
44
40
|
"main": "main.js",
|
|
45
41
|
"description": "An implementation of the Google Workspace Apps Script runtime: Run native App Script Code on Node and Cloud Run",
|
package/src/support/sxzip.js
CHANGED
|
@@ -5,19 +5,9 @@
|
|
|
5
5
|
* note
|
|
6
6
|
* - arguments and returns must be serializable ie. primitives or plain objects
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import unzipper from 'unzipper';
|
|
8
|
+
import AdmZip from 'adm-zip';
|
|
10
9
|
import { syncWarn, syncError } from './workersync/synclogger.js';
|
|
11
10
|
|
|
12
|
-
const streamToBuffer = (stream) => {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
const chunks = [];
|
|
15
|
-
stream.on('data', chunk => chunks.push(chunk));
|
|
16
|
-
stream.on('error', err => reject(err));
|
|
17
|
-
stream.on('end', () => resolve(Buffer.concat(chunks)));
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
11
|
/**
|
|
22
12
|
* create a zipped version of multiple files
|
|
23
13
|
* @param {object} p params
|
|
@@ -25,23 +15,14 @@ const streamToBuffer = (stream) => {
|
|
|
25
15
|
* @return {byte[]} the zipped content
|
|
26
16
|
*/
|
|
27
17
|
export const sxZipper = async (_Auth, { blobsContent }) => {
|
|
28
|
-
|
|
29
|
-
const archive = archiver.create('zip', {});
|
|
30
|
-
|
|
31
18
|
try {
|
|
32
|
-
|
|
33
|
-
archive.on('warning', (err) => syncWarn(`Archiver warning: ${err}`));
|
|
34
|
-
|
|
35
|
-
// Start collecting the buffer in parallel. This promise resolves when the stream ends.
|
|
36
|
-
const bufferPromise = streamToBuffer(archive);
|
|
19
|
+
const zip = new AdmZip();
|
|
37
20
|
|
|
38
21
|
blobsContent.forEach((f) => {
|
|
39
|
-
|
|
22
|
+
zip.addFile(f.name, Buffer.from(f.bytes));
|
|
40
23
|
});
|
|
41
24
|
|
|
42
|
-
|
|
43
|
-
// for finalization to be complete. This is the most robust way.
|
|
44
|
-
const [buffer] = await Promise.all([bufferPromise, archive.finalize()]);
|
|
25
|
+
const buffer = zip.toBuffer();
|
|
45
26
|
return Array.from(buffer);
|
|
46
27
|
} catch (err) {
|
|
47
28
|
syncError('sxZipper failed', err);
|
|
@@ -56,23 +37,24 @@ export const sxZipper = async (_Auth, { blobsContent }) => {
|
|
|
56
37
|
* @return {SerializedBlob[]} the unzipped content
|
|
57
38
|
*/
|
|
58
39
|
export const sxUnzipper = async (_Auth, { blobContent }) => {
|
|
59
|
-
|
|
60
|
-
const buffer = Buffer.from(blobContent.bytes)
|
|
61
|
-
const unzipped = await unzipper.Open.buffer(buffer)
|
|
62
|
-
|
|
63
|
-
// By wrapping the Promise.all in a try/catch, we ensure that if any
|
|
64
|
-
// single file stream fails, the entire operation rejects cleanly.
|
|
65
40
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
41
|
+
const buffer = Buffer.from(blobContent.bytes);
|
|
42
|
+
const zip = new AdmZip(buffer);
|
|
43
|
+
const zipEntries = zip.getEntries();
|
|
44
|
+
|
|
45
|
+
// Ignore directory entries (they end with a slash)
|
|
46
|
+
const result = zipEntries
|
|
47
|
+
.filter(zipEntry => !zipEntry.isDirectory)
|
|
48
|
+
.map(zipEntry => {
|
|
49
|
+
return {
|
|
50
|
+
bytes: Array.from(zipEntry.getData()),
|
|
51
|
+
name: zipEntry.entryName
|
|
52
|
+
};
|
|
53
|
+
});
|
|
72
54
|
|
|
73
55
|
return result;
|
|
74
56
|
} catch (err) {
|
|
75
57
|
syncError('An error occurred while unzipping a file stream inside the archive.', err);
|
|
76
|
-
throw err;
|
|
58
|
+
throw err;
|
|
77
59
|
}
|
|
78
60
|
}
|