@zip.js/zip.js 2.7.7 → 2.7.8
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/zip-fs-full.js +112 -44
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +112 -44
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +6 -3
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-inflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +6 -3
- package/dist/zip.min.js +1 -1
- package/index.cjs +112 -44
- package/index.d.ts +29 -0
- package/lib/core/zip-fs-core.js +107 -42
- package/lib/core/zip-reader.js +6 -3
- package/package.json +1 -1
package/dist/zip-fs.js
CHANGED
|
@@ -3525,10 +3525,13 @@
|
|
|
3525
3525
|
}
|
|
3526
3526
|
}
|
|
3527
3527
|
const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
|
|
3528
|
+
const size = compressedSize;
|
|
3528
3529
|
const readable = reader.readable;
|
|
3529
|
-
readable
|
|
3530
|
-
|
|
3531
|
-
|
|
3530
|
+
Object.assign(readable, {
|
|
3531
|
+
diskNumberStart,
|
|
3532
|
+
offset: dataOffset,
|
|
3533
|
+
size
|
|
3534
|
+
});
|
|
3532
3535
|
const signal = getOptionValue$1(zipEntry, options, "signal");
|
|
3533
3536
|
const checkPasswordOnly = getOptionValue$1(zipEntry, options, "checkPasswordOnly");
|
|
3534
3537
|
if (checkPasswordOnly) {
|
|
@@ -5149,7 +5152,26 @@
|
|
|
5149
5152
|
}
|
|
5150
5153
|
|
|
5151
5154
|
addFileSystemEntry(fileSystemEntry, options = {}) {
|
|
5152
|
-
return
|
|
5155
|
+
return addFileSystemHandle(this, fileSystemEntry, options);
|
|
5156
|
+
}
|
|
5157
|
+
|
|
5158
|
+
addFileSystemHandle(handle, options = {}) {
|
|
5159
|
+
return addFileSystemHandle(this, handle, options);
|
|
5160
|
+
}
|
|
5161
|
+
|
|
5162
|
+
addFile(file, options = {}) {
|
|
5163
|
+
if (!options.lastModDate) {
|
|
5164
|
+
options.lastModDate = new Date(file.lastModified);
|
|
5165
|
+
}
|
|
5166
|
+
return addChild(this, file.name, {
|
|
5167
|
+
data: file,
|
|
5168
|
+
Reader: function () {
|
|
5169
|
+
const readable = file.stream();
|
|
5170
|
+
const size = file.size;
|
|
5171
|
+
return { readable, size };
|
|
5172
|
+
},
|
|
5173
|
+
options
|
|
5174
|
+
});
|
|
5153
5175
|
}
|
|
5154
5176
|
|
|
5155
5177
|
addData(name, params) {
|
|
@@ -5352,6 +5374,14 @@
|
|
|
5352
5374
|
return this.root.addFileSystemEntry(fileSystemEntry, options);
|
|
5353
5375
|
}
|
|
5354
5376
|
|
|
5377
|
+
addFileSystemHandle(handle, options) {
|
|
5378
|
+
return this.root.addFileSystemHandle(handle, options);
|
|
5379
|
+
}
|
|
5380
|
+
|
|
5381
|
+
addFile(file, options) {
|
|
5382
|
+
return this.root.addFile(file, options);
|
|
5383
|
+
}
|
|
5384
|
+
|
|
5355
5385
|
addData(name, params) {
|
|
5356
5386
|
return this.root.addData(name, params);
|
|
5357
5387
|
}
|
|
@@ -5542,54 +5572,92 @@
|
|
|
5542
5572
|
}
|
|
5543
5573
|
}
|
|
5544
5574
|
|
|
5545
|
-
async function
|
|
5546
|
-
|
|
5547
|
-
const entry = zipEntry.addDirectory(fileSystemEntry.name, options);
|
|
5548
|
-
await addDirectory(entry, fileSystemEntry);
|
|
5549
|
-
return entry;
|
|
5550
|
-
} else {
|
|
5551
|
-
return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file, options)), reject));
|
|
5552
|
-
}
|
|
5575
|
+
async function addFileSystemHandle(zipEntry, handle, options) {
|
|
5576
|
+
await addFile(zipEntry, handle, []);
|
|
5553
5577
|
|
|
5554
|
-
async function
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
await
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5578
|
+
async function addFile(parentEntry, handle, addedEntries) {
|
|
5579
|
+
try {
|
|
5580
|
+
if (handle.isFile || handle.isDirectory) {
|
|
5581
|
+
handle = transformToFileSystemhandle(handle);
|
|
5582
|
+
}
|
|
5583
|
+
if (handle.kind == "file") {
|
|
5584
|
+
const file = await handle.getFile();
|
|
5585
|
+
addedEntries.push(
|
|
5586
|
+
parentEntry.addData(file.name, {
|
|
5587
|
+
Reader: function () {
|
|
5588
|
+
const readable = file.stream();
|
|
5589
|
+
const size = file.size;
|
|
5590
|
+
return { readable, size };
|
|
5591
|
+
},
|
|
5592
|
+
options: {
|
|
5593
|
+
lastModDate: new Date(file.lastModified)
|
|
5594
|
+
}
|
|
5595
|
+
}, options)
|
|
5596
|
+
);
|
|
5597
|
+
} else if (handle.kind == "directory") {
|
|
5598
|
+
const directoryEntry = parentEntry.addDirectory(handle.name);
|
|
5599
|
+
addedEntries.push(directoryEntry);
|
|
5600
|
+
for await (const childHandle of handle.values()) {
|
|
5601
|
+
await addFile(directoryEntry, childHandle, addedEntries);
|
|
5602
|
+
}
|
|
5567
5603
|
}
|
|
5604
|
+
} catch (error) {
|
|
5605
|
+
const message = error.message + (handle ? " (" + handle.name + ")" : "");
|
|
5606
|
+
throw new Error(message);
|
|
5568
5607
|
}
|
|
5608
|
+
return addedEntries;
|
|
5569
5609
|
}
|
|
5610
|
+
}
|
|
5570
5611
|
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5612
|
+
async function transformToFileSystemhandle(entry) {
|
|
5613
|
+
const handle = {
|
|
5614
|
+
name: entry.name
|
|
5615
|
+
};
|
|
5616
|
+
if (entry.isFile) {
|
|
5617
|
+
handle.kind = "file";
|
|
5618
|
+
handle.getFile = () =>
|
|
5619
|
+
new Promise((resolve, reject) => entry.file(resolve, reject));
|
|
5620
|
+
}
|
|
5621
|
+
if (entry.isDirectory) {
|
|
5622
|
+
handle.kind = "directory";
|
|
5623
|
+
const handles = await transformToFileSystemhandles(entry);
|
|
5624
|
+
handle.values = () => handles;
|
|
5625
|
+
}
|
|
5626
|
+
return handle;
|
|
5627
|
+
}
|
|
5580
5628
|
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5629
|
+
async function transformToFileSystemhandles(entry) {
|
|
5630
|
+
const entries = [];
|
|
5631
|
+
function readEntries(directoryReader, resolve, reject) {
|
|
5632
|
+
directoryReader.readEntries(async (entriesPart) => {
|
|
5633
|
+
if (!entriesPart.length) {
|
|
5634
|
+
resolve(entries);
|
|
5635
|
+
} else {
|
|
5636
|
+
for (const entry of entriesPart) {
|
|
5637
|
+
entries.push(await transformToFileSystemhandle(entry));
|
|
5638
|
+
}
|
|
5639
|
+
readEntries(directoryReader, resolve, reject);
|
|
5590
5640
|
}
|
|
5591
|
-
});
|
|
5641
|
+
}, reject);
|
|
5592
5642
|
}
|
|
5643
|
+
await new Promise((resolve, reject) =>
|
|
5644
|
+
readEntries(entry.createReader(), resolve, reject)
|
|
5645
|
+
);
|
|
5646
|
+
return {
|
|
5647
|
+
[Symbol.iterator]() {
|
|
5648
|
+
let entryIndex = 0;
|
|
5649
|
+
return {
|
|
5650
|
+
next() {
|
|
5651
|
+
const result = {
|
|
5652
|
+
value: entries[entryIndex],
|
|
5653
|
+
done: entryIndex === entries.length
|
|
5654
|
+
};
|
|
5655
|
+
entryIndex++;
|
|
5656
|
+
return result;
|
|
5657
|
+
}
|
|
5658
|
+
};
|
|
5659
|
+
}
|
|
5660
|
+
};
|
|
5593
5661
|
}
|
|
5594
5662
|
|
|
5595
5663
|
function resetFS(fs) {
|