@zip.js/zip.js 2.8.31 → 2.8.32
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/BENCHMARKS.md +82 -1
- package/deno.json +1 -1
- package/dist/zip-core.js +270 -5
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core.js +1 -1
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-native.js +273 -8
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +270 -5
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +272 -7
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +273 -8
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip.js +270 -5
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +273 -8
- package/index-native.min.js +1 -1
- package/index.cjs +270 -5
- package/index.d.cts +40 -1
- package/index.d.ts +40 -1
- package/index.min.js +1 -1
- package/lib/core/codec-worker.js +1 -1
- package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
- package/lib/core/util/blob-temp-stream.js +124 -0
- package/lib/core/util/sync-access-handle-temp-stream.js +147 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/zip-core-base.js +7 -1
- package/package.json +1 -1
package/dist/zip-fs.js
CHANGED
|
@@ -2451,7 +2451,7 @@
|
|
|
2451
2451
|
const { value, readable, writable } = message;
|
|
2452
2452
|
const transferables = [];
|
|
2453
2453
|
if (value) {
|
|
2454
|
-
message.value = value;
|
|
2454
|
+
message.value = value.byteOffset || value.byteLength != value.buffer.byteLength ? new Uint8Array(value) : value;
|
|
2455
2455
|
transferables.push(message.value.buffer);
|
|
2456
2456
|
}
|
|
2457
2457
|
if (transferStreams && transferStreamsSupported) {
|
|
@@ -6652,13 +6652,13 @@
|
|
|
6652
6652
|
*/
|
|
6653
6653
|
|
|
6654
6654
|
|
|
6655
|
-
const DEFAULT_THRESHOLD = 1024 * 1024;
|
|
6656
|
-
const DEFAULT_DIRECTORY_NAME = ".zip.js-temp";
|
|
6655
|
+
const DEFAULT_THRESHOLD$2 = 1024 * 1024;
|
|
6656
|
+
const DEFAULT_DIRECTORY_NAME$1 = ".zip.js-temp";
|
|
6657
6657
|
|
|
6658
6658
|
function createOPFSTempStream(options = {}) {
|
|
6659
6659
|
const {
|
|
6660
|
-
thresholdBytes = DEFAULT_THRESHOLD,
|
|
6661
|
-
directoryName = DEFAULT_DIRECTORY_NAME,
|
|
6660
|
+
thresholdBytes = DEFAULT_THRESHOLD$2,
|
|
6661
|
+
directoryName = DEFAULT_DIRECTORY_NAME$1,
|
|
6662
6662
|
getDirectory = () => navigator.storage.getDirectory()
|
|
6663
6663
|
} = options;
|
|
6664
6664
|
let directoryHandlePromise;
|
|
@@ -6787,6 +6787,269 @@
|
|
|
6787
6787
|
*/
|
|
6788
6788
|
|
|
6789
6789
|
|
|
6790
|
+
const DEFAULT_THRESHOLD$1 = 1024 * 1024;
|
|
6791
|
+
|
|
6792
|
+
function createBlobTempStream(options = {}) {
|
|
6793
|
+
const {
|
|
6794
|
+
thresholdBytes = DEFAULT_THRESHOLD$1
|
|
6795
|
+
} = options;
|
|
6796
|
+
return function () {
|
|
6797
|
+
const memoryChunks = [];
|
|
6798
|
+
let bufferedSize = 0;
|
|
6799
|
+
let spilled = false;
|
|
6800
|
+
let blobWriter, blobPromise, blobReader;
|
|
6801
|
+
|
|
6802
|
+
async function spillToBlob() {
|
|
6803
|
+
const transformStream = new TransformStream();
|
|
6804
|
+
blobPromise = new Response(transformStream.readable).blob();
|
|
6805
|
+
blobWriter = transformStream.writable.getWriter();
|
|
6806
|
+
spilled = true;
|
|
6807
|
+
for (const chunk of memoryChunks) {
|
|
6808
|
+
await blobWriter.write(chunk);
|
|
6809
|
+
}
|
|
6810
|
+
memoryChunks.length = 0;
|
|
6811
|
+
}
|
|
6812
|
+
|
|
6813
|
+
const writable = new WritableStream({
|
|
6814
|
+
async write(chunk) {
|
|
6815
|
+
if (spilled) {
|
|
6816
|
+
await blobWriter.write(chunk);
|
|
6817
|
+
} else {
|
|
6818
|
+
memoryChunks.push(chunk);
|
|
6819
|
+
bufferedSize += chunk.length;
|
|
6820
|
+
if (bufferedSize > thresholdBytes) {
|
|
6821
|
+
await spillToBlob();
|
|
6822
|
+
}
|
|
6823
|
+
}
|
|
6824
|
+
},
|
|
6825
|
+
async close() {
|
|
6826
|
+
if (blobWriter) {
|
|
6827
|
+
await blobWriter.close();
|
|
6828
|
+
blobWriter = null;
|
|
6829
|
+
}
|
|
6830
|
+
}
|
|
6831
|
+
});
|
|
6832
|
+
|
|
6833
|
+
let memoryIndex = 0;
|
|
6834
|
+
const readable = new ReadableStream({
|
|
6835
|
+
async pull(controller) {
|
|
6836
|
+
if (spilled) {
|
|
6837
|
+
if (!blobReader) {
|
|
6838
|
+
const blob = await blobPromise;
|
|
6839
|
+
blobReader = blob.stream().getReader();
|
|
6840
|
+
}
|
|
6841
|
+
const { value, done } = await blobReader.read();
|
|
6842
|
+
if (done) {
|
|
6843
|
+
controller.close();
|
|
6844
|
+
} else {
|
|
6845
|
+
controller.enqueue(value);
|
|
6846
|
+
}
|
|
6847
|
+
} else if (memoryIndex < memoryChunks.length) {
|
|
6848
|
+
controller.enqueue(memoryChunks[memoryIndex++]);
|
|
6849
|
+
} else {
|
|
6850
|
+
controller.close();
|
|
6851
|
+
}
|
|
6852
|
+
},
|
|
6853
|
+
async cancel(reason) {
|
|
6854
|
+
if (blobReader) {
|
|
6855
|
+
await blobReader.cancel(reason);
|
|
6856
|
+
}
|
|
6857
|
+
}
|
|
6858
|
+
}, { highWaterMark: 0 });
|
|
6859
|
+
async function dispose() {
|
|
6860
|
+
if (blobWriter) {
|
|
6861
|
+
try {
|
|
6862
|
+
await blobWriter.abort();
|
|
6863
|
+
} catch {
|
|
6864
|
+
// ignored
|
|
6865
|
+
}
|
|
6866
|
+
blobWriter = null;
|
|
6867
|
+
}
|
|
6868
|
+
if (blobPromise) {
|
|
6869
|
+
blobPromise.catch(() => {
|
|
6870
|
+
// ignored
|
|
6871
|
+
});
|
|
6872
|
+
blobPromise = null;
|
|
6873
|
+
}
|
|
6874
|
+
memoryChunks.length = 0;
|
|
6875
|
+
}
|
|
6876
|
+
|
|
6877
|
+
return { writable, readable, dispose };
|
|
6878
|
+
};
|
|
6879
|
+
}
|
|
6880
|
+
|
|
6881
|
+
/*
|
|
6882
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
6883
|
+
|
|
6884
|
+
Redistribution and use in source and binary forms, with or without
|
|
6885
|
+
modification, are permitted provided that the following conditions are met:
|
|
6886
|
+
|
|
6887
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
6888
|
+
this list of conditions and the following disclaimer.
|
|
6889
|
+
|
|
6890
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
6891
|
+
notice, this list of conditions and the following disclaimer in
|
|
6892
|
+
the documentation and/or other materials provided with the distribution.
|
|
6893
|
+
|
|
6894
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
6895
|
+
derived from this software without specific prior written permission.
|
|
6896
|
+
|
|
6897
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
6898
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
6899
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
6900
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
6901
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
6902
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
6903
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
6904
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
6905
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
6906
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
6907
|
+
*/
|
|
6908
|
+
|
|
6909
|
+
|
|
6910
|
+
const DEFAULT_THRESHOLD = 1024 * 1024;
|
|
6911
|
+
const DEFAULT_DIRECTORY_NAME = ".zip.js-temp";
|
|
6912
|
+
const READ_CHUNK_SIZE = 512 * 1024;
|
|
6913
|
+
const ERR_UNSUPPORTED_CONTEXT = "createSyncAccessHandle is only available in dedicated workers";
|
|
6914
|
+
|
|
6915
|
+
function createSyncAccessHandleTempStream(options = {}) {
|
|
6916
|
+
const {
|
|
6917
|
+
thresholdBytes = DEFAULT_THRESHOLD,
|
|
6918
|
+
directoryName = DEFAULT_DIRECTORY_NAME,
|
|
6919
|
+
getDirectory
|
|
6920
|
+
} = options;
|
|
6921
|
+
if (!getDirectory &&
|
|
6922
|
+
(typeof FileSystemFileHandle == "undefined" || !FileSystemFileHandle.prototype.createSyncAccessHandle)) {
|
|
6923
|
+
throw new Error(ERR_UNSUPPORTED_CONTEXT);
|
|
6924
|
+
}
|
|
6925
|
+
const getRootDirectory = getDirectory || (() => navigator.storage.getDirectory());
|
|
6926
|
+
let directoryHandlePromise;
|
|
6927
|
+
function getTempDirectory() {
|
|
6928
|
+
if (!directoryHandlePromise) {
|
|
6929
|
+
directoryHandlePromise = Promise.resolve(getRootDirectory())
|
|
6930
|
+
.then(root => root.getDirectoryHandle(directoryName, { create: true }));
|
|
6931
|
+
}
|
|
6932
|
+
return directoryHandlePromise;
|
|
6933
|
+
}
|
|
6934
|
+
return function () {
|
|
6935
|
+
const memoryChunks = [];
|
|
6936
|
+
let bufferedSize = 0;
|
|
6937
|
+
let spilled = false;
|
|
6938
|
+
let fileName, accessHandle;
|
|
6939
|
+
let writeOffset = 0;
|
|
6940
|
+
let readOffset = 0;
|
|
6941
|
+
|
|
6942
|
+
async function spillToFile() {
|
|
6943
|
+
const directoryHandle = await getTempDirectory();
|
|
6944
|
+
fileName = crypto.randomUUID();
|
|
6945
|
+
const fileHandle = await directoryHandle.getFileHandle(fileName, { create: true });
|
|
6946
|
+
accessHandle = await fileHandle.createSyncAccessHandle();
|
|
6947
|
+
spilled = true;
|
|
6948
|
+
for (const chunk of memoryChunks) {
|
|
6949
|
+
accessHandle.write(chunk, { at: writeOffset });
|
|
6950
|
+
writeOffset += chunk.length;
|
|
6951
|
+
}
|
|
6952
|
+
memoryChunks.length = 0;
|
|
6953
|
+
}
|
|
6954
|
+
|
|
6955
|
+
const writable = new WritableStream({
|
|
6956
|
+
async write(chunk) {
|
|
6957
|
+
if (spilled) {
|
|
6958
|
+
accessHandle.write(chunk, { at: writeOffset });
|
|
6959
|
+
writeOffset += chunk.length;
|
|
6960
|
+
} else {
|
|
6961
|
+
memoryChunks.push(chunk);
|
|
6962
|
+
bufferedSize += chunk.length;
|
|
6963
|
+
if (bufferedSize > thresholdBytes) {
|
|
6964
|
+
await spillToFile();
|
|
6965
|
+
}
|
|
6966
|
+
}
|
|
6967
|
+
},
|
|
6968
|
+
close() {
|
|
6969
|
+
if (accessHandle) {
|
|
6970
|
+
accessHandle.flush();
|
|
6971
|
+
}
|
|
6972
|
+
}
|
|
6973
|
+
});
|
|
6974
|
+
|
|
6975
|
+
let memoryIndex = 0;
|
|
6976
|
+
const readable = new ReadableStream({
|
|
6977
|
+
pull(controller) {
|
|
6978
|
+
if (spilled) {
|
|
6979
|
+
const remaining = writeOffset - readOffset;
|
|
6980
|
+
if (remaining <= 0) {
|
|
6981
|
+
controller.close();
|
|
6982
|
+
return;
|
|
6983
|
+
}
|
|
6984
|
+
const buffer = new Uint8Array(Math.min(READ_CHUNK_SIZE, remaining));
|
|
6985
|
+
const read = accessHandle.read(buffer, { at: readOffset });
|
|
6986
|
+
if (read) {
|
|
6987
|
+
readOffset += read;
|
|
6988
|
+
controller.enqueue(buffer.subarray(0, read));
|
|
6989
|
+
} else {
|
|
6990
|
+
controller.close();
|
|
6991
|
+
}
|
|
6992
|
+
} else if (memoryIndex < memoryChunks.length) {
|
|
6993
|
+
controller.enqueue(memoryChunks[memoryIndex++]);
|
|
6994
|
+
} else {
|
|
6995
|
+
controller.close();
|
|
6996
|
+
}
|
|
6997
|
+
}
|
|
6998
|
+
}, { highWaterMark: 0 });
|
|
6999
|
+
async function dispose() {
|
|
7000
|
+
if (accessHandle) {
|
|
7001
|
+
try {
|
|
7002
|
+
accessHandle.close();
|
|
7003
|
+
} catch {
|
|
7004
|
+
// ignored
|
|
7005
|
+
}
|
|
7006
|
+
accessHandle = null;
|
|
7007
|
+
}
|
|
7008
|
+
if (fileName) {
|
|
7009
|
+
try {
|
|
7010
|
+
const directoryHandle = await getTempDirectory();
|
|
7011
|
+
await directoryHandle.removeEntry(fileName);
|
|
7012
|
+
} catch {
|
|
7013
|
+
// ignored
|
|
7014
|
+
}
|
|
7015
|
+
fileName = null;
|
|
7016
|
+
}
|
|
7017
|
+
memoryChunks.length = 0;
|
|
7018
|
+
}
|
|
7019
|
+
|
|
7020
|
+
return { writable, readable, dispose };
|
|
7021
|
+
};
|
|
7022
|
+
}
|
|
7023
|
+
|
|
7024
|
+
/*
|
|
7025
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
7026
|
+
|
|
7027
|
+
Redistribution and use in source and binary forms, with or without
|
|
7028
|
+
modification, are permitted provided that the following conditions are met:
|
|
7029
|
+
|
|
7030
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
7031
|
+
this list of conditions and the following disclaimer.
|
|
7032
|
+
|
|
7033
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
7034
|
+
notice, this list of conditions and the following disclaimer in
|
|
7035
|
+
the documentation and/or other materials provided with the distribution.
|
|
7036
|
+
|
|
7037
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
7038
|
+
derived from this software without specific prior written permission.
|
|
7039
|
+
|
|
7040
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
7041
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
7042
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
7043
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
7044
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
7045
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
7046
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
7047
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
7048
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
7049
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7050
|
+
*/
|
|
7051
|
+
|
|
7052
|
+
|
|
6790
7053
|
try {
|
|
6791
7054
|
configure({ baseURI: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('zip-fs.js', document.baseURI).href)) });
|
|
6792
7055
|
} catch {
|
|
@@ -9877,7 +10140,9 @@
|
|
|
9877
10140
|
exports.ZipWriter = ZipWriter;
|
|
9878
10141
|
exports.ZipWriterStream = ZipWriterStream;
|
|
9879
10142
|
exports.configure = configure;
|
|
10143
|
+
exports.createBlobTempStream = createBlobTempStream;
|
|
9880
10144
|
exports.createOPFSTempStream = createOPFSTempStream;
|
|
10145
|
+
exports.createSyncAccessHandleTempStream = createSyncAccessHandleTempStream;
|
|
9881
10146
|
exports.fs = fs;
|
|
9882
10147
|
exports.getMimeType = getMimeType;
|
|
9883
10148
|
exports.terminateWorkers = terminateWorkersAndModule;
|