@zip.js/zip.js 2.8.59 → 2.8.61
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/deno.json +2 -2
- package/dist/zip-core-external.js +167 -37
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +143 -20
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +173 -45
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +5326 -3928
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +173 -45
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +151 -30
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +176 -45
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +145 -22
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +145 -22
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +170 -37
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +151 -30
- package/index-native.min.js +1 -1
- package/index.cjs +176 -45
- package/index.d.cts +134 -1
- package/index.d.ts +134 -1
- package/index.min.js +1 -1
- package/lib/core/codec-registry.js +5 -0
- package/lib/core/compression-methods.js +93 -0
- package/lib/core/streams/zip-entry-stream.js +7 -3
- package/lib/core/streams/zlib-wasm/zlib-streams.js +18 -8
- package/lib/core/version.js +31 -0
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-fs.js +5 -4
- package/lib/core/zip-writer.js +38 -31
- package/lib/zip-core-base.js +7 -0
- package/lib/zip-fs-core.js +32 -0
- package/package.json +4 -3
- package/release.sh +47 -0
- package/sync-versions.js +26 -0
package/lib/core/zip-writer.js
CHANGED
|
@@ -56,17 +56,16 @@
|
|
|
56
56
|
* the insertion order of the `fileEntries` map. addFile() reserves each entry's slot synchronously in
|
|
57
57
|
* add() call order, before initializing the reader, so concurrent entries whose readers
|
|
58
58
|
* initialize at different speeds are still listed in call order.
|
|
59
|
-
* - `fileEntry.lockFileEntry` chains every entry to the previous one
|
|
60
|
-
*
|
|
61
|
-
* the
|
|
62
|
-
*
|
|
59
|
+
* - `fileEntry.lockFileEntry` chains every entry to the previous one; awaiting it serializes the
|
|
60
|
+
* physical writes when `keepOrder` is set. addFile() claims the link in the same synchronous
|
|
61
|
+
* prologue as the central directory slot, so the physical layout follows the add() call order
|
|
62
|
+
* as well, whatever the readers do. The lock is released for every entry, including the ones
|
|
63
|
+
* failing before they reach getFileEntry().
|
|
63
64
|
* - `zipWriter.lockWriter`/`writerLocked` is the mutex over the writer; only the holder may write
|
|
64
65
|
* into it or read the position variables above.
|
|
65
|
-
* -
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* before awaiting the lock of the previous entry, while a buffered predecessor needs the
|
|
69
|
-
* writer lock to be flushed.
|
|
66
|
+
* - Both write paths await the lock of the previous entry before requesting the writer lock.
|
|
67
|
+
* Requesting it first would deadlock an entry written directly into the writer (i.e. without
|
|
68
|
+
* being buffered) against a buffered predecessor, which needs that same lock to be flushed.
|
|
70
69
|
* - `lastFileEntry` is the tail of the lock chain (the most recently added entry).
|
|
71
70
|
*
|
|
72
71
|
* Failures:
|
|
@@ -689,6 +688,13 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
689
688
|
const { comment } = metadataInfo;
|
|
690
689
|
const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
|
|
691
690
|
zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
|
|
691
|
+
const previousFileEntry = zipWriter.lastFileEntry;
|
|
692
|
+
const pendingFileEntry = {};
|
|
693
|
+
let releaseLockFileEntry;
|
|
694
|
+
if (metadataInfo.resolvedOptions.keepOrder) {
|
|
695
|
+
pendingFileEntry.lockFileEntry = new Promise(resolve => releaseLockFileEntry = resolve);
|
|
696
|
+
}
|
|
697
|
+
zipWriter.lastFileEntry = pendingFileEntry;
|
|
692
698
|
let fileEntry;
|
|
693
699
|
try {
|
|
694
700
|
const { resolvedOptions } = metadataInfo;
|
|
@@ -710,10 +716,21 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
710
716
|
const headerInfo = getHeaderInfo(options);
|
|
711
717
|
const dataDescriptorInfo = getDataDescriptorInfo(options);
|
|
712
718
|
const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
|
|
713
|
-
fileEntry = await getFileEntry(zipWriter, name, reader, {
|
|
719
|
+
fileEntry = await getFileEntry(zipWriter, name, reader, {
|
|
720
|
+
headerInfo,
|
|
721
|
+
dataDescriptorInfo,
|
|
722
|
+
metadataSize,
|
|
723
|
+
fileEntry: pendingFileEntry,
|
|
724
|
+
previousFileEntry,
|
|
725
|
+
releaseLockFileEntry
|
|
726
|
+
}, options);
|
|
714
727
|
} catch (error) {
|
|
715
728
|
zipWriter.fileEntries.delete(name);
|
|
716
729
|
throw error;
|
|
730
|
+
} finally {
|
|
731
|
+
if (releaseLockFileEntry) {
|
|
732
|
+
releaseLockFileEntry(previousFileEntry && previousFileEntry.lockFileEntry);
|
|
733
|
+
}
|
|
717
734
|
}
|
|
718
735
|
Object.assign(fileEntry, {
|
|
719
736
|
name,
|
|
@@ -1101,7 +1118,6 @@ async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comm
|
|
|
1101
1118
|
}
|
|
1102
1119
|
const usdz = writerOptions[OPTION_USDZ];
|
|
1103
1120
|
const files = new Map();
|
|
1104
|
-
let layoutDependsOnWriteOrder = Boolean(usdz);
|
|
1105
1121
|
const initialOffset = writerOptions[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : writerOptions[OPTION_OFFSET];
|
|
1106
1122
|
let offset = initialOffset;
|
|
1107
1123
|
let minimumEntrySize = INFINITY_VALUE;
|
|
@@ -1147,9 +1163,7 @@ async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comm
|
|
|
1147
1163
|
minimumEntrySize = Math.min(minimumEntrySize, entrySize);
|
|
1148
1164
|
offset += entrySize;
|
|
1149
1165
|
}
|
|
1150
|
-
|
|
1151
|
-
layoutDependsOnWriteOrder = true;
|
|
1152
|
-
}
|
|
1166
|
+
const layoutDependsOnWriteOrder = files.size > 1 && (usdz || offset - minimumEntrySize >= MAX_32_BITS);
|
|
1153
1167
|
if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
|
|
1154
1168
|
throw new Error(ERR_UNDETERMINED_SIZE);
|
|
1155
1169
|
}
|
|
@@ -1177,27 +1191,23 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
1177
1191
|
signal
|
|
1178
1192
|
} = options;
|
|
1179
1193
|
const {
|
|
1180
|
-
headerInfo
|
|
1194
|
+
headerInfo,
|
|
1195
|
+
fileEntry: pendingFileEntry,
|
|
1196
|
+
previousFileEntry,
|
|
1197
|
+
releaseLockFileEntry
|
|
1181
1198
|
} = entryInfo;
|
|
1182
1199
|
const usdz = zipWriter.options[OPTION_USDZ];
|
|
1183
|
-
|
|
1184
|
-
let fileEntry = {};
|
|
1200
|
+
let fileEntry = pendingFileEntry;
|
|
1185
1201
|
let bufferedWrite;
|
|
1186
1202
|
let releaseLockWriter;
|
|
1187
|
-
let releaseLockCurrentFileEntry;
|
|
1188
1203
|
let writingBufferedEntryData;
|
|
1189
1204
|
let writingEntryData;
|
|
1190
1205
|
let writerSizeBeforeEntry;
|
|
1191
1206
|
let flushedBufferedSize = 0;
|
|
1192
1207
|
let fileWriter;
|
|
1208
|
+
const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
|
|
1193
1209
|
fileEntries.set(name, fileEntry);
|
|
1194
|
-
zipWriter.lastFileEntry = fileEntry;
|
|
1195
1210
|
try {
|
|
1196
|
-
let lockPreviousFileEntry;
|
|
1197
|
-
if (keepOrder) {
|
|
1198
|
-
lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
|
|
1199
|
-
requestLockCurrentFileEntry();
|
|
1200
|
-
}
|
|
1201
1211
|
if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
|
|
1202
1212
|
bufferedWrite = true;
|
|
1203
1213
|
zipWriter.bufferedWrites++;
|
|
@@ -1210,6 +1220,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
1210
1220
|
await initStream(writer);
|
|
1211
1221
|
} else {
|
|
1212
1222
|
fileWriter = writer;
|
|
1223
|
+
await lockPreviousFileEntry;
|
|
1213
1224
|
await requestLockWriter();
|
|
1214
1225
|
}
|
|
1215
1226
|
await initStream(fileWriter);
|
|
@@ -1222,7 +1233,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
1222
1233
|
}
|
|
1223
1234
|
const { localHeaderArray } = headerInfo;
|
|
1224
1235
|
if (!bufferedWrite) {
|
|
1225
|
-
await lockPreviousFileEntry;
|
|
1226
1236
|
await skipDiskIfNeeded();
|
|
1227
1237
|
}
|
|
1228
1238
|
const diskNumberStart = getDiskNumber(writer);
|
|
@@ -1287,8 +1297,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
1287
1297
|
if (bufferedWrite) {
|
|
1288
1298
|
zipWriter.bufferedWrites--;
|
|
1289
1299
|
}
|
|
1290
|
-
if (
|
|
1291
|
-
|
|
1300
|
+
if (releaseLockFileEntry) {
|
|
1301
|
+
releaseLockFileEntry(lockPreviousFileEntry);
|
|
1292
1302
|
}
|
|
1293
1303
|
if (releaseLockWriter) {
|
|
1294
1304
|
releaseLockWriter();
|
|
@@ -1302,10 +1312,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
1302
1312
|
}
|
|
1303
1313
|
}
|
|
1304
1314
|
|
|
1305
|
-
function requestLockCurrentFileEntry() {
|
|
1306
|
-
fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
1315
|
async function requestLockWriter() {
|
|
1310
1316
|
zipWriter.writerLocked = true;
|
|
1311
1317
|
const { lockWriter } = zipWriter;
|
|
@@ -1440,6 +1446,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
|
|
|
1440
1446
|
const workerOptions = {
|
|
1441
1447
|
options: {
|
|
1442
1448
|
codecType: CODEC_DEFLATE,
|
|
1449
|
+
inputSize: size,
|
|
1443
1450
|
level,
|
|
1444
1451
|
rawPassword,
|
|
1445
1452
|
password,
|
package/lib/zip-core-base.js
CHANGED
|
@@ -71,10 +71,17 @@ export {
|
|
|
71
71
|
export {
|
|
72
72
|
registerCodec,
|
|
73
73
|
unregisterCodec,
|
|
74
|
+
getRegisteredCodecs,
|
|
74
75
|
ERR_INVALID_CODEC_DEFINITION,
|
|
75
76
|
ERR_RESERVED_COMPRESSION_METHOD,
|
|
76
77
|
ERR_INVALID_CODEC_MODULE
|
|
77
78
|
} from "./core/codec-registry.js";
|
|
79
|
+
export {
|
|
80
|
+
getSupportedCompressionMethods
|
|
81
|
+
} from "./core/compression-methods.js";
|
|
82
|
+
export {
|
|
83
|
+
VERSION
|
|
84
|
+
} from "./core/version.js";
|
|
78
85
|
export {
|
|
79
86
|
createOPFSTempStream
|
|
80
87
|
} from "./core/util/opfs-temp-stream.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="../index.d.ts" />
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Copyright (c) 2025 Gildas Lormeau. All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer in
|
|
14
|
+
the documentation and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
17
|
+
derived from this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
20
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
22
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
23
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
25
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
26
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
28
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export * from "./zip-core.js";
|
|
32
|
+
export * from "./core/zip-fs.js";
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
|
|
4
4
|
"author": "Gildas Lormeau",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
|
-
"version": "2.8.
|
|
6
|
+
"version": "2.8.61",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"zip",
|
|
@@ -34,11 +34,12 @@
|
|
|
34
34
|
"bun": ">=0.7.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"version": "node ./sync-
|
|
37
|
+
"version": "node ./sync-versions.js && git add deno.json lib/core/version.js",
|
|
38
38
|
"bump-patch": "npm version patch --no-git-tag-version && npm run bump-commit",
|
|
39
39
|
"bump-minor": "npm version minor --no-git-tag-version && npm run bump-commit",
|
|
40
40
|
"bump-major": "npm version major --no-git-tag-version && npm run bump-commit",
|
|
41
|
-
"bump-commit": "git commit -m \"bump up version\" package.json package-lock.json deno.json",
|
|
41
|
+
"bump-commit": "npm run build && git commit -m \"bump up version\" package.json package-lock.json deno.json lib/core/version.js dist index.cjs index-native.cjs index.min.js index-native.min.js lib/core/web-worker-inline-wasm.js lib/core/web-worker-inline-native.js",
|
|
42
|
+
"release": "sh ./release.sh",
|
|
42
43
|
"lint": "npx eslint . && deno lint",
|
|
43
44
|
"test": "npm run test-node && npm run test-deno && npm run test-bun && npm run test-node-dist && npm run test-deno-dist && npm run test-bun-dist && npm run test-web-streams-polyfill && npm run test-types && npm run test-api-symmetry && npm run test-api-shape && npm run test-api-mangling",
|
|
44
45
|
"test-browsers": "npm run test-chrome && npm run test-firefox && npm run test-safari",
|
package/release.sh
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Creates the GitHub release for the version declared in package.json, which triggers the publish
|
|
3
|
+
# workflow. It only encodes the checks a release must pass anyway: the released commit is the pushed
|
|
4
|
+
# master head, its tests concluded green (the publish gate would otherwise fail after the release
|
|
5
|
+
# exists, and recovering means deleting the release and the tag), and the tag targets the branch
|
|
6
|
+
# because the API rejects abbreviated commit SHAs as a target.
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
notes_file=$1
|
|
10
|
+
if [ -z "$notes_file" ]; then
|
|
11
|
+
echo "usage: npm run release -- <notes-file>" >&2
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
if [ ! -f "$notes_file" ]; then
|
|
15
|
+
echo "notes file not found: $notes_file" >&2
|
|
16
|
+
exit 1
|
|
17
|
+
fi
|
|
18
|
+
version=$(node -p "require('./package.json').version")
|
|
19
|
+
tag="v$version"
|
|
20
|
+
if gh release view "$tag" >/dev/null 2>&1; then
|
|
21
|
+
echo "release $tag already exists" >&2
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
25
|
+
echo "the working tree is not clean" >&2
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
git fetch origin master
|
|
29
|
+
sha=$(git rev-parse HEAD)
|
|
30
|
+
if [ "$sha" != "$(git rev-parse origin/master)" ]; then
|
|
31
|
+
echo "HEAD is not origin/master, push the bump commit first" >&2
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
run=$(gh api "repos/{owner}/{repo}/actions/workflows/test.yml/runs?head_sha=$sha&per_page=1" \
|
|
35
|
+
--jq 'if (.workflow_runs | length) == 0 then "none none none" else (.workflow_runs[0] | "\(.status) \(.conclusion) \(.html_url)") end')
|
|
36
|
+
run_status=$(echo "$run" | cut -d " " -f 1)
|
|
37
|
+
conclusion=$(echo "$run" | cut -d " " -f 2)
|
|
38
|
+
url=$(echo "$run" | cut -d " " -f 3)
|
|
39
|
+
if [ "$run_status" = "none" ]; then
|
|
40
|
+
echo "no test run found for $sha yet, wait for it and run this again" >&2
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
if [ "$run_status" != "completed" ] || [ "$conclusion" != "success" ]; then
|
|
44
|
+
echo "the tests of $sha concluded $run_status/$conclusion, only a green commit can be released: $url" >&2
|
|
45
|
+
exit 1
|
|
46
|
+
fi
|
|
47
|
+
gh release create "$tag" --target master --notes-file "$notes_file"
|
package/sync-versions.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const JSON_VERSION_REGEXP = /("version"\s*:\s*")[^"]*(")/;
|
|
6
|
+
const LIB_VERSION_REGEXP = /(const VERSION = ")[^"]*(")/;
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const PACKAGE_PATH = path.resolve(__dirname, "package.json");
|
|
10
|
+
const DENO_PATH = path.resolve(__dirname, "deno.json");
|
|
11
|
+
const LIB_VERSION_PATH = path.resolve(__dirname, "lib", "core", "version.js");
|
|
12
|
+
|
|
13
|
+
const { version } = JSON.parse(fs.readFileSync(PACKAGE_PATH, "utf8"));
|
|
14
|
+
syncVersion(DENO_PATH, JSON_VERSION_REGEXP);
|
|
15
|
+
syncVersion(LIB_VERSION_PATH, LIB_VERSION_REGEXP);
|
|
16
|
+
|
|
17
|
+
function syncVersion(filePath, versionRegExp) {
|
|
18
|
+
const source = fs.readFileSync(filePath, "utf8");
|
|
19
|
+
if (!versionRegExp.test(source)) {
|
|
20
|
+
throw new Error("no version found in " + path.basename(filePath));
|
|
21
|
+
}
|
|
22
|
+
const syncedSource = source.replace(versionRegExp, "$1" + version + "$2");
|
|
23
|
+
if (syncedSource != source) {
|
|
24
|
+
fs.writeFileSync(filePath, syncedSource);
|
|
25
|
+
}
|
|
26
|
+
}
|