keycloakify 7.6.3 → 7.6.4

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.
Files changed (39) hide show
  1. package/account/kcContext/KcContext.d.ts +1 -0
  2. package/account/kcContext/KcContext.js.map +1 -1
  3. package/account/kcContext/kcContextMocks.js +1 -0
  4. package/account/kcContext/kcContextMocks.js.map +1 -1
  5. package/bin/eject-keycloak-page.js +6 -6
  6. package/bin/eject-keycloak-page.js.map +1 -1
  7. package/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +2 -2
  8. package/bin/keycloakify/generateFtl/generateFtl.d.ts +1 -0
  9. package/bin/keycloakify/generateFtl/generateFtl.js +4 -5
  10. package/bin/keycloakify/generateFtl/generateFtl.js.map +1 -1
  11. package/bin/keycloakify/generateKeycloakThemeResources.d.ts +1 -0
  12. package/bin/keycloakify/generateKeycloakThemeResources.js +4 -3
  13. package/bin/keycloakify/generateKeycloakThemeResources.js.map +1 -1
  14. package/bin/keycloakify/keycloakify.js +7 -1
  15. package/bin/keycloakify/keycloakify.js.map +1 -1
  16. package/bin/tools/jar.d.ts +19 -3
  17. package/bin/tools/jar.js +151 -58
  18. package/bin/tools/jar.js.map +1 -1
  19. package/bin/tools/walk.d.ts +1 -1
  20. package/login/kcContext/KcContext.d.ts +1 -0
  21. package/login/kcContext/KcContext.js.map +1 -1
  22. package/login/kcContext/kcContextMocks.js +1 -0
  23. package/login/kcContext/kcContextMocks.js.map +1 -1
  24. package/package.json +3 -5
  25. package/src/account/kcContext/KcContext.ts +1 -0
  26. package/src/account/kcContext/kcContextMocks.ts +1 -0
  27. package/src/bin/eject-keycloak-page.ts +2 -4
  28. package/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +2 -2
  29. package/src/bin/keycloakify/generateFtl/generateFtl.ts +4 -3
  30. package/src/bin/keycloakify/generateKeycloakThemeResources.ts +4 -2
  31. package/src/bin/keycloakify/keycloakify.ts +9 -1
  32. package/src/bin/tools/jar.ts +58 -65
  33. package/src/bin/tools/walk.ts +1 -1
  34. package/src/login/kcContext/KcContext.ts +1 -0
  35. package/src/login/kcContext/kcContextMocks.ts +1 -0
  36. package/bin/tools/zip.d.ts +0 -29
  37. package/bin/tools/zip.js +0 -330
  38. package/bin/tools/zip.js.map +0 -1
  39. package/src/bin/tools/zip.ts +0 -246
package/bin/tools/zip.js DELETED
@@ -1,330 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __values = (this && this.__values) || function(o) {
39
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
- if (m) return m.call(o);
41
- if (o && typeof o.length === "number") return {
42
- next: function () {
43
- if (o && i >= o.length) o = void 0;
44
- return { value: o && o[i++], done: !o };
45
- }
46
- };
47
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var stream_1 = require("stream");
51
- var fs_1 = require("fs");
52
- var promises_1 = require("fs/promises");
53
- var buffer_1 = require("buffer");
54
- var deflate_1 = require("./deflate");
55
- /**
56
- * @returns the actual byte size of an string
57
- */
58
- function utf8size(s) {
59
- return new buffer_1.Blob([s]).size;
60
- }
61
- /**
62
- * @param record
63
- * @returns a buffer representing a Zip local header
64
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#Local_file_header
65
- */
66
- function localHeader(record) {
67
- var path = record.path, compression = record.compression, uncompressedSize = record.uncompressedSize;
68
- var filenameSize = utf8size(path);
69
- var buf = Buffer.alloc(30 + filenameSize);
70
- buf.writeUInt32LE(67324752, 0); // local header signature
71
- buf.writeUInt16LE(10, 4); // min version
72
- // we write 0x08 because crc and compressed size are unknown at
73
- buf.writeUInt16LE(0x08, 6); // general purpose bit flag
74
- buf.writeUInt16LE(compression ? { "deflate": 8 }[compression] : 0, 8);
75
- buf.writeUInt16LE(0, 10); // modified time
76
- buf.writeUInt16LE(0, 12); // modified date
77
- buf.writeUInt32LE(0, 14); // crc unknown
78
- buf.writeUInt32LE(0, 18); // compressed size unknown
79
- buf.writeUInt32LE(uncompressedSize, 22);
80
- buf.writeUInt16LE(filenameSize, 26);
81
- buf.writeUInt16LE(0, 28); // extra field length
82
- buf.write(path, 30, "utf-8");
83
- return buf;
84
- }
85
- /**
86
- * @param record
87
- * @returns a buffer representing a Zip central header
88
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_directory_file_header
89
- */
90
- function centralHeader(record) {
91
- var path = record.path, compression = record.compression, crc32 = record.crc32, compressedSize = record.compressedSize, uncompressedSize = record.uncompressedSize, offset = record.offset;
92
- var filenameSize = utf8size(path);
93
- var buf = Buffer.alloc(46 + filenameSize);
94
- var isFile = !path.endsWith("/");
95
- if (typeof offset === "undefined")
96
- throw new Error("Illegal argument");
97
- // we don't want to deal with possibly messed up file or directory
98
- // permissions, so we ignore the original permissions
99
- var externalAttr = isFile ? 0x81a40000 : 0x41ed0000;
100
- buf.writeUInt32LE(33639248, 0); // central header signature
101
- buf.writeUInt16LE(10, 4); // version
102
- buf.writeUInt16LE(10, 6); // min version
103
- buf.writeUInt16LE(0, 8); // general purpose bit flag
104
- buf.writeUInt16LE(compression ? { "deflate": 8 }[compression] : 0, 10);
105
- buf.writeUInt16LE(0, 12); // modified time
106
- buf.writeUInt16LE(0, 14); // modified date
107
- buf.writeUInt32LE(crc32 || 0, 16);
108
- buf.writeUInt32LE(compressedSize || 0, 20);
109
- buf.writeUInt32LE(uncompressedSize, 24);
110
- buf.writeUInt16LE(filenameSize, 28);
111
- buf.writeUInt16LE(0, 30); // extra field length
112
- buf.writeUInt16LE(0, 32); // comment field length
113
- buf.writeUInt16LE(0, 34); // disk number
114
- buf.writeUInt16LE(0, 36); // internal
115
- buf.writeUInt32LE(externalAttr, 38); // external
116
- buf.writeUInt32LE(offset, 42); // offset where file starts
117
- buf.write(path, 46, "utf-8");
118
- return buf;
119
- }
120
- /**
121
- * @returns a buffer representing an Zip End-Of-Central-Directory block
122
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#End_of_central_directory_record_(EOCD)
123
- */
124
- function eocd(_a) {
125
- var offset = _a.offset, cdSize = _a.cdSize, nRecords = _a.nRecords;
126
- var buf = Buffer.alloc(22);
127
- buf.writeUint32LE(0x06054b50, 0); // eocd signature
128
- buf.writeUInt16LE(0, 4); // disc number
129
- buf.writeUint16LE(0, 6); // disc where central directory starts
130
- buf.writeUint16LE(nRecords, 8); // records on this disc
131
- buf.writeUInt16LE(nRecords, 10); // records total
132
- buf.writeUInt32LE(cdSize, 12); // byte size of cd
133
- buf.writeUInt32LE(offset, 16); // cd offset
134
- buf.writeUint16LE(0, 20); // comment length
135
- return buf;
136
- }
137
- /**
138
- * @returns a stream Transform, which reads a stream of ZipRecords and
139
- * writes a bytestream
140
- */
141
- function zip() {
142
- var _this = this;
143
- /**
144
- * This is called when the input stream of ZipSource items is finished.
145
- * Will write central directory and end-of-central-direcotry blocks.
146
- */
147
- var final = function () {
148
- var e_1, _a;
149
- // write central directory
150
- var cdSize = 0;
151
- try {
152
- for (var records_1 = __values(records), records_1_1 = records_1.next(); !records_1_1.done; records_1_1 = records_1.next()) {
153
- var record = records_1_1.value;
154
- var head = centralHeader(record);
155
- zipTransform.push(head);
156
- cdSize += head.length;
157
- }
158
- }
159
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
160
- finally {
161
- try {
162
- if (records_1_1 && !records_1_1.done && (_a = records_1.return)) _a.call(records_1);
163
- }
164
- finally { if (e_1) throw e_1.error; }
165
- }
166
- // write end-of-central-directory
167
- zipTransform.push(eocd({ offset: offset, cdSize: cdSize, nRecords: records.length }));
168
- // signal stream end
169
- zipTransform.push(null);
170
- };
171
- /**
172
- * Write a directory entry to the archive
173
- * @param path
174
- */
175
- var writeDir = function (path) { return __awaiter(_this, void 0, void 0, function () {
176
- var record, head;
177
- return __generator(this, function (_a) {
178
- record = {
179
- path: path + "/",
180
- offset: offset,
181
- compression: undefined,
182
- uncompressedSize: 0
183
- };
184
- head = localHeader(record);
185
- zipTransform.push(head);
186
- records.push(record);
187
- offset += head.length;
188
- return [2 /*return*/];
189
- });
190
- }); };
191
- /**
192
- * Write a file entry to the archive
193
- * @param archivePath path of the file in archive
194
- * @param fsPath path to file on filesystem
195
- * @param size of the actual, uncompressed, file
196
- */
197
- var writeFile = function (archivePath, fsPath, size) { return __awaiter(_this, void 0, void 0, function () {
198
- var record, head, _a, crc32, compressedSize;
199
- return __generator(this, function (_b) {
200
- switch (_b.label) {
201
- case 0:
202
- record = {
203
- path: archivePath,
204
- offset: offset,
205
- compression: "deflate",
206
- uncompressedSize: size
207
- };
208
- head = localHeader(record);
209
- zipTransform.push(head);
210
- return [4 /*yield*/, (0, deflate_1.deflateStream)((0, fs_1.createReadStream)(fsPath), function (chunk) { return zipTransform.push(chunk); })];
211
- case 1:
212
- _a = _b.sent(), crc32 = _a.crc32, compressedSize = _a.compressedSize;
213
- record.crc32 = crc32;
214
- record.compressedSize = compressedSize;
215
- records.push(record);
216
- offset += head.length + compressedSize;
217
- return [2 /*return*/];
218
- }
219
- });
220
- }); };
221
- /**
222
- * Write archive record based on filesystem file or directory
223
- * @param archivePath path of item in archive
224
- * @param fsPath path to item on filesystem
225
- */
226
- var writeFromPath = function (archivePath, fsPath) { return __awaiter(_this, void 0, void 0, function () {
227
- var fileStats, _a;
228
- return __generator(this, function (_b) {
229
- switch (_b.label) {
230
- case 0: return [4 /*yield*/, (0, promises_1.stat)(fsPath)];
231
- case 1:
232
- fileStats = _b.sent();
233
- if (!fileStats.isDirectory()) return [3 /*break*/, 3];
234
- return [4 /*yield*/, writeDir(archivePath)]; /**/
235
- case 2:
236
- _a = _b.sent(); /**/
237
- return [3 /*break*/, 5];
238
- case 3: return [4 /*yield*/, writeFile(archivePath, fsPath, fileStats.size)]; /**/
239
- case 4:
240
- _a = _b.sent(); /**/
241
- _b.label = 5;
242
- case 5:
243
- _a;
244
- return [2 /*return*/];
245
- }
246
- });
247
- }); };
248
- /**
249
- * Write archive record based on data in a buffer
250
- * @param path
251
- * @param data
252
- */
253
- var writeFromBuffer = function (path, data) { return __awaiter(_this, void 0, void 0, function () {
254
- var _a, deflated, crc32, record, head;
255
- return __generator(this, function (_b) {
256
- switch (_b.label) {
257
- case 0: return [4 /*yield*/, (0, deflate_1.deflateBuffer)(data)];
258
- case 1:
259
- _a = _b.sent(), deflated = _a.deflated, crc32 = _a.crc32;
260
- record = {
261
- path: path,
262
- compression: "deflate",
263
- crc32: crc32,
264
- uncompressedSize: data.length,
265
- compressedSize: deflated.length,
266
- offset: offset
267
- };
268
- head = localHeader(record);
269
- zipTransform.push(head);
270
- zipTransform.push(deflated);
271
- records.push(record);
272
- offset += head.length + deflated.length;
273
- return [2 /*return*/];
274
- }
275
- });
276
- }); };
277
- /**
278
- * Write an archive record
279
- * @param source
280
- */
281
- var writeRecord = function (source) { return __awaiter(_this, void 0, void 0, function () {
282
- return __generator(this, function (_a) {
283
- switch (_a.label) {
284
- case 0:
285
- if (!("fsPath" in source)) return [3 /*break*/, 2];
286
- return [4 /*yield*/, writeFromPath(source.path, source.fsPath)];
287
- case 1:
288
- _a.sent();
289
- return [3 /*break*/, 5];
290
- case 2:
291
- if (!("data" in source)) return [3 /*break*/, 4];
292
- return [4 /*yield*/, writeFromBuffer(source.path, source.data)];
293
- case 3:
294
- _a.sent();
295
- return [3 /*break*/, 5];
296
- case 4: throw new Error("Illegal argument " + typeof source + " " + JSON.stringify(source));
297
- case 5: return [2 /*return*/];
298
- }
299
- });
300
- }); };
301
- /**
302
- * The actual stream transform function
303
- * @param source
304
- * @param _ encoding, ignored
305
- * @param cb
306
- */
307
- var transform = function (source, _, cb) { return __awaiter(_this, void 0, void 0, function () {
308
- return __generator(this, function (_a) {
309
- switch (_a.label) {
310
- case 0: return [4 /*yield*/, writeRecord(source)];
311
- case 1:
312
- _a.sent();
313
- cb();
314
- return [2 /*return*/];
315
- }
316
- });
317
- }); };
318
- /** offset and records keep local state during processing */
319
- var offset = 0;
320
- var records = [];
321
- var zipTransform = new stream_1.Transform({
322
- readableObjectMode: false,
323
- writableObjectMode: true,
324
- transform: transform,
325
- final: final
326
- });
327
- return zipTransform;
328
- }
329
- exports.default = zip;
330
- //# sourceMappingURL=zip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../src/bin/tools/zip.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAqD;AACrD,yBAAsC;AACtC,wCAAmC;AACnC,iCAA8B;AAE9B,qCAAyD;AAmBzD;;GAEG;AACH,SAAS,QAAQ,CAAC,CAAS;IACvB,OAAO,IAAI,aAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,MAAiB;IAC1B,IAAA,IAAI,GAAoC,MAAM,KAA1C,EAAE,WAAW,GAAuB,MAAM,YAA7B,EAAE,gBAAgB,GAAK,MAAM,iBAAX,CAAY;IACvD,IAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACpC,IAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IAE5C,GAAG,CAAC,aAAa,CAAC,QAAa,EAAE,CAAC,CAAC,CAAC,CAAC,yBAAyB;IAC9D,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc;IACxC,+DAA+D;IAC/D,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,2BAA2B;IACvD,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAE,EAAE,SAAS,EAAE,CAAC,EAAY,CAAC,WAAW,CAAC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A8HC"}
@@ -1,246 +0,0 @@
1
- import { Transform, TransformOptions } from "stream";
2
- import { createReadStream } from "fs";
3
- import { stat } from "fs/promises";
4
- import { Blob } from "buffer";
5
-
6
- import { deflateBuffer, deflateStream } from "./deflate";
7
-
8
- /**
9
- * Zip source
10
- * @property filename the name of the entry in the archie
11
- * @property path of the source file, if the source is an actual file
12
- * @property data the actual data buffer, if the source is constructed in-memory
13
- */
14
- export type ZipSource = { path: string } & ({ fsPath: string } | { data: Buffer });
15
-
16
- export type ZipRecord = {
17
- path: string;
18
- compression: "deflate" | undefined;
19
- uncompressedSize: number;
20
- compressedSize?: number;
21
- crc32?: number;
22
- offset?: number;
23
- };
24
-
25
- /**
26
- * @returns the actual byte size of an string
27
- */
28
- function utf8size(s: string) {
29
- return new Blob([s]).size;
30
- }
31
-
32
- /**
33
- * @param record
34
- * @returns a buffer representing a Zip local header
35
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#Local_file_header
36
- */
37
- function localHeader(record: ZipRecord) {
38
- const { path, compression, uncompressedSize } = record;
39
- const filenameSize = utf8size(path);
40
- const buf = Buffer.alloc(30 + filenameSize);
41
-
42
- buf.writeUInt32LE(0x04_03_4b_50, 0); // local header signature
43
- buf.writeUInt16LE(10, 4); // min version
44
- // we write 0x08 because crc and compressed size are unknown at
45
- buf.writeUInt16LE(0x08, 6); // general purpose bit flag
46
- buf.writeUInt16LE(compression ? ({ "deflate": 8 } as const)[compression] : 0, 8);
47
- buf.writeUInt16LE(0, 10); // modified time
48
- buf.writeUInt16LE(0, 12); // modified date
49
- buf.writeUInt32LE(0, 14); // crc unknown
50
- buf.writeUInt32LE(0, 18); // compressed size unknown
51
- buf.writeUInt32LE(uncompressedSize, 22);
52
- buf.writeUInt16LE(filenameSize, 26);
53
- buf.writeUInt16LE(0, 28); // extra field length
54
- buf.write(path, 30, "utf-8");
55
-
56
- return buf;
57
- }
58
-
59
- /**
60
- * @param record
61
- * @returns a buffer representing a Zip central header
62
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_directory_file_header
63
- */
64
- function centralHeader(record: ZipRecord) {
65
- const { path, compression, crc32, compressedSize, uncompressedSize, offset } = record;
66
- const filenameSize = utf8size(path);
67
- const buf = Buffer.alloc(46 + filenameSize);
68
- const isFile = !path.endsWith("/");
69
-
70
- if (typeof offset === "undefined") throw new Error("Illegal argument");
71
-
72
- // we don't want to deal with possibly messed up file or directory
73
- // permissions, so we ignore the original permissions
74
- const externalAttr = isFile ? 0x81a40000 : 0x41ed0000;
75
-
76
- buf.writeUInt32LE(0x0201_4b50, 0); // central header signature
77
- buf.writeUInt16LE(10, 4); // version
78
- buf.writeUInt16LE(10, 6); // min version
79
- buf.writeUInt16LE(0, 8); // general purpose bit flag
80
- buf.writeUInt16LE(compression ? ({ "deflate": 8 } as const)[compression] : 0, 10);
81
- buf.writeUInt16LE(0, 12); // modified time
82
- buf.writeUInt16LE(0, 14); // modified date
83
- buf.writeUInt32LE(crc32 || 0, 16);
84
- buf.writeUInt32LE(compressedSize || 0, 20);
85
- buf.writeUInt32LE(uncompressedSize, 24);
86
- buf.writeUInt16LE(filenameSize, 28);
87
- buf.writeUInt16LE(0, 30); // extra field length
88
- buf.writeUInt16LE(0, 32); // comment field length
89
- buf.writeUInt16LE(0, 34); // disk number
90
- buf.writeUInt16LE(0, 36); // internal
91
- buf.writeUInt32LE(externalAttr, 38); // external
92
- buf.writeUInt32LE(offset, 42); // offset where file starts
93
- buf.write(path, 46, "utf-8");
94
-
95
- return buf;
96
- }
97
-
98
- /**
99
- * @returns a buffer representing an Zip End-Of-Central-Directory block
100
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#End_of_central_directory_record_(EOCD)
101
- */
102
- function eocd({ offset, cdSize, nRecords }: { offset: number; cdSize: number; nRecords: number }) {
103
- const buf = Buffer.alloc(22);
104
- buf.writeUint32LE(0x06054b50, 0); // eocd signature
105
- buf.writeUInt16LE(0, 4); // disc number
106
- buf.writeUint16LE(0, 6); // disc where central directory starts
107
- buf.writeUint16LE(nRecords, 8); // records on this disc
108
- buf.writeUInt16LE(nRecords, 10); // records total
109
- buf.writeUInt32LE(cdSize, 12); // byte size of cd
110
- buf.writeUInt32LE(offset, 16); // cd offset
111
- buf.writeUint16LE(0, 20); // comment length
112
-
113
- return buf;
114
- }
115
-
116
- /**
117
- * @returns a stream Transform, which reads a stream of ZipRecords and
118
- * writes a bytestream
119
- */
120
- export default function zip() {
121
- /**
122
- * This is called when the input stream of ZipSource items is finished.
123
- * Will write central directory and end-of-central-direcotry blocks.
124
- */
125
- const final = () => {
126
- // write central directory
127
- let cdSize = 0;
128
- for (const record of records) {
129
- const head = centralHeader(record);
130
- zipTransform.push(head);
131
- cdSize += head.length;
132
- }
133
-
134
- // write end-of-central-directory
135
- zipTransform.push(eocd({ offset, cdSize, nRecords: records.length }));
136
- // signal stream end
137
- zipTransform.push(null);
138
- };
139
-
140
- /**
141
- * Write a directory entry to the archive
142
- * @param path
143
- */
144
- const writeDir = async (path: string) => {
145
- const record: ZipRecord = {
146
- path: path + "/",
147
- offset,
148
- compression: undefined,
149
- uncompressedSize: 0
150
- };
151
- const head = localHeader(record);
152
- zipTransform.push(head);
153
- records.push(record);
154
- offset += head.length;
155
- };
156
-
157
- /**
158
- * Write a file entry to the archive
159
- * @param archivePath path of the file in archive
160
- * @param fsPath path to file on filesystem
161
- * @param size of the actual, uncompressed, file
162
- */
163
- const writeFile = async (archivePath: string, fsPath: string, size: number) => {
164
- const record: ZipRecord = {
165
- path: archivePath,
166
- offset,
167
- compression: "deflate",
168
- uncompressedSize: size
169
- };
170
- const head = localHeader(record);
171
- zipTransform.push(head);
172
-
173
- const { crc32, compressedSize } = await deflateStream(createReadStream(fsPath), chunk => zipTransform.push(chunk));
174
-
175
- record.crc32 = crc32;
176
- record.compressedSize = compressedSize;
177
- records.push(record);
178
- offset += head.length + compressedSize;
179
- };
180
-
181
- /**
182
- * Write archive record based on filesystem file or directory
183
- * @param archivePath path of item in archive
184
- * @param fsPath path to item on filesystem
185
- */
186
- const writeFromPath = async (archivePath: string, fsPath: string) => {
187
- const fileStats = await stat(fsPath);
188
- fileStats.isDirectory() ? await writeDir(archivePath) /**/ : await writeFile(archivePath, fsPath, fileStats.size) /**/;
189
- };
190
-
191
- /**
192
- * Write archive record based on data in a buffer
193
- * @param path
194
- * @param data
195
- */
196
- const writeFromBuffer = async (path: string, data: Buffer) => {
197
- const { deflated, crc32 } = await deflateBuffer(data);
198
- const record: ZipRecord = {
199
- path,
200
- compression: "deflate",
201
- crc32,
202
- uncompressedSize: data.length,
203
- compressedSize: deflated.length,
204
- offset
205
- };
206
- const head = localHeader(record);
207
- zipTransform.push(head);
208
- zipTransform.push(deflated);
209
- records.push(record);
210
- offset += head.length + deflated.length;
211
- };
212
-
213
- /**
214
- * Write an archive record
215
- * @param source
216
- */
217
- const writeRecord = async (source: ZipSource) => {
218
- if ("fsPath" in source) await writeFromPath(source.path, source.fsPath);
219
- else if ("data" in source) await writeFromBuffer(source.path, source.data);
220
- else throw new Error("Illegal argument " + typeof source + " " + JSON.stringify(source));
221
- };
222
-
223
- /**
224
- * The actual stream transform function
225
- * @param source
226
- * @param _ encoding, ignored
227
- * @param cb
228
- */
229
- const transform: TransformOptions["transform"] = async (source: ZipSource, _, cb) => {
230
- await writeRecord(source);
231
- cb();
232
- };
233
-
234
- /** offset and records keep local state during processing */
235
- let offset = 0;
236
- const records: ZipRecord[] = [];
237
-
238
- const zipTransform = new Transform({
239
- readableObjectMode: false,
240
- writableObjectMode: true,
241
- transform,
242
- final
243
- });
244
-
245
- return zipTransform;
246
- }