@loaders.gl/zip 4.3.4 → 4.4.0-alpha.10
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/dist.dev.js +275 -248
- package/dist/dist.min.js +2 -2
- package/dist/filesystems/IndexedArchive.d.ts +4 -4
- package/dist/filesystems/IndexedArchive.d.ts.map +1 -1
- package/dist/filesystems/IndexedArchive.js +6 -5
- package/dist/filesystems/IndexedArchive.js.map +1 -0
- package/dist/filesystems/zip-filesystem.d.ts +7 -6
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
- package/dist/filesystems/zip-filesystem.js +25 -22
- package/dist/filesystems/zip-filesystem.js.map +1 -0
- package/dist/hash-file-utility.d.ts +3 -3
- package/dist/hash-file-utility.d.ts.map +1 -1
- package/dist/hash-file-utility.js +2 -1
- package/dist/hash-file-utility.js.map +1 -0
- package/dist/index.cjs +181 -82
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/tar/header.js +1 -0
- package/dist/lib/tar/header.js.map +1 -0
- package/dist/lib/tar/tar.js +1 -0
- package/dist/lib/tar/tar.js.map +1 -0
- package/dist/lib/tar/types.js +1 -0
- package/dist/lib/tar/types.js.map +1 -0
- package/dist/lib/tar/utils.js +1 -0
- package/dist/lib/tar/utils.js.map +1 -0
- package/dist/parse-zip/cd-file-header.d.ts +4 -4
- package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
- package/dist/parse-zip/cd-file-header.js +9 -6
- package/dist/parse-zip/cd-file-header.js.map +1 -0
- package/dist/parse-zip/end-of-central-directory.d.ts +3 -3
- package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -1
- package/dist/parse-zip/end-of-central-directory.js +13 -11
- package/dist/parse-zip/end-of-central-directory.js.map +1 -0
- package/dist/parse-zip/local-file-header.d.ts +2 -2
- package/dist/parse-zip/local-file-header.d.ts.map +1 -1
- package/dist/parse-zip/local-file-header.js +5 -3
- package/dist/parse-zip/local-file-header.js.map +1 -0
- package/dist/parse-zip/readable-file-utils.d.ts +34 -0
- package/dist/parse-zip/readable-file-utils.d.ts.map +1 -0
- package/dist/parse-zip/readable-file-utils.js +111 -0
- package/dist/parse-zip/readable-file-utils.js.map +1 -0
- package/dist/parse-zip/search-from-the-end.d.ts +2 -2
- package/dist/parse-zip/search-from-the-end.d.ts.map +1 -1
- package/dist/parse-zip/search-from-the-end.js +7 -8
- package/dist/parse-zip/search-from-the-end.js.map +1 -0
- package/dist/parse-zip/zip-composition.d.ts.map +1 -1
- package/dist/parse-zip/zip-composition.js +16 -8
- package/dist/parse-zip/zip-composition.js.map +1 -0
- package/dist/parse-zip/zip64-info-generation.js +1 -0
- package/dist/parse-zip/zip64-info-generation.js.map +1 -0
- package/dist/tar-builder.js +1 -0
- package/dist/tar-builder.js.map +1 -0
- package/dist/zip-loader.js +2 -1
- package/dist/zip-loader.js.map +1 -0
- package/dist/zip-writer.js +3 -2
- package/dist/zip-writer.js.map +1 -0
- package/package.json +6 -6
- package/src/filesystems/IndexedArchive.ts +6 -10
- package/src/filesystems/zip-filesystem.ts +26 -28
- package/src/hash-file-utility.ts +4 -7
- package/src/index.ts +5 -0
- package/src/parse-zip/cd-file-header.ts +18 -16
- package/src/parse-zip/end-of-central-directory.ts +16 -17
- package/src/parse-zip/local-file-header.ts +8 -9
- package/src/parse-zip/readable-file-utils.ts +134 -0
- package/src/parse-zip/search-from-the-end.ts +8 -10
- package/src/parse-zip/zip-composition.ts +25 -18
- package/src/zip-writer.ts +1 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FileHandleFile,
|
|
3
2
|
concatenateArrayBuffers,
|
|
4
3
|
path,
|
|
5
4
|
NodeFilesystem,
|
|
6
|
-
NodeFile
|
|
5
|
+
NodeFile,
|
|
6
|
+
toArrayBuffer
|
|
7
7
|
} from '@loaders.gl/loader-utils';
|
|
8
8
|
import {ZipEoCDRecord, generateEoCD, parseEoCDRecord, updateEoCD} from './end-of-central-directory';
|
|
9
9
|
import {CRC32Hash} from '@loaders.gl/crypto';
|
|
10
10
|
import {generateLocalHeader} from './local-file-header';
|
|
11
11
|
import {generateCDHeader} from './cd-file-header';
|
|
12
12
|
import {fetchFile} from '@loaders.gl/core';
|
|
13
|
+
import {readRange} from './readable-file-utils';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* cut off CD and EoCD records from zip file
|
|
@@ -17,11 +18,12 @@ import {fetchFile} from '@loaders.gl/core';
|
|
|
17
18
|
* @returns tuple with three values: CD, EoCD record, EoCD information
|
|
18
19
|
*/
|
|
19
20
|
async function cutTheTailOff(
|
|
20
|
-
provider:
|
|
21
|
+
provider: NodeFile
|
|
21
22
|
): Promise<[ArrayBuffer, ArrayBuffer, ZipEoCDRecord]> {
|
|
22
23
|
// define where the body ends
|
|
23
24
|
const oldEoCDinfo = await parseEoCDRecord(provider);
|
|
24
25
|
const oldCDStartOffset = oldEoCDinfo.cdStartOffset;
|
|
26
|
+
const providerSize = (await provider.stat()).bigsize;
|
|
25
27
|
|
|
26
28
|
// define cd length
|
|
27
29
|
const oldCDLength = Number(
|
|
@@ -31,7 +33,7 @@ async function cutTheTailOff(
|
|
|
31
33
|
);
|
|
32
34
|
|
|
33
35
|
// cut off everything except of archieve body
|
|
34
|
-
const zipEnding = await provider
|
|
36
|
+
const zipEnding = await readRange(provider, oldCDStartOffset, providerSize);
|
|
35
37
|
await provider.truncate(Number(oldCDStartOffset));
|
|
36
38
|
|
|
37
39
|
// divide cd body and eocd record
|
|
@@ -84,39 +86,44 @@ async function generateFileHeaders(
|
|
|
84
86
|
*/
|
|
85
87
|
export async function addOneFile(zipUrl: string, fileToAdd: ArrayBuffer, fileName: string) {
|
|
86
88
|
// init file handler
|
|
87
|
-
const provider = new
|
|
89
|
+
const provider = new NodeFile(zipUrl, 'a+');
|
|
88
90
|
|
|
89
91
|
const [oldCDBody, eocdBody, oldEoCDinfo] = await cutTheTailOff(provider);
|
|
90
92
|
|
|
93
|
+
let currentOffset = (await provider.stat()).bigsize;
|
|
94
|
+
|
|
91
95
|
// remember the new file local header start offset
|
|
92
|
-
const newFileOffset =
|
|
96
|
+
const newFileOffset = currentOffset;
|
|
93
97
|
|
|
94
98
|
const [localPart, cdHeaderPart] = await generateFileHeaders(fileName, fileToAdd, newFileOffset);
|
|
95
99
|
|
|
96
100
|
// write down the file local header
|
|
97
101
|
await provider.append(localPart);
|
|
102
|
+
currentOffset += BigInt(localPart.byteLength);
|
|
98
103
|
|
|
99
104
|
// add the file CD header to the CD
|
|
100
105
|
const newCDBody = concatenateArrayBuffers(oldCDBody, cdHeaderPart);
|
|
101
106
|
|
|
102
107
|
// remember the CD start offset
|
|
103
|
-
const newCDStartOffset =
|
|
108
|
+
const newCDStartOffset = currentOffset;
|
|
104
109
|
|
|
105
110
|
// write down new CD
|
|
106
111
|
await provider.append(new Uint8Array(newCDBody));
|
|
112
|
+
currentOffset += BigInt(newCDBody.byteLength);
|
|
107
113
|
|
|
108
114
|
// remember where eocd starts
|
|
109
|
-
const eocdOffset =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
oldEoCDinfo.cdRecordsNumber + 1n
|
|
118
|
-
)
|
|
115
|
+
const eocdOffset = currentOffset;
|
|
116
|
+
|
|
117
|
+
const updatedEoCD = updateEoCD(
|
|
118
|
+
eocdBody,
|
|
119
|
+
oldEoCDinfo.offsets,
|
|
120
|
+
newCDStartOffset,
|
|
121
|
+
eocdOffset,
|
|
122
|
+
oldEoCDinfo.cdRecordsNumber + 1n
|
|
119
123
|
);
|
|
124
|
+
|
|
125
|
+
await provider.append(updatedEoCD);
|
|
126
|
+
currentOffset += BigInt(updatedEoCD.byteLength);
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
/**
|
|
@@ -173,7 +180,7 @@ async function addFile(
|
|
|
173
180
|
fileList?.push({fileName: file.path, localHeaderOffset: size});
|
|
174
181
|
const [localPart, cdHeaderPart] = await generateFileHeaders(file.path, file.file, size);
|
|
175
182
|
await resFile.append(localPart);
|
|
176
|
-
cdArray.push(cdHeaderPart);
|
|
183
|
+
cdArray.push(toArrayBuffer(cdHeaderPart));
|
|
177
184
|
}
|
|
178
185
|
|
|
179
186
|
/**
|
package/src/zip-writer.ts
CHANGED