@loaders.gl/zip
Advanced tools
Comparing version 4.1.0-alpha.3 to 4.1.0-alpha.4
@@ -45,3 +45,3 @@ import { FileProvider } from '@loaders.gl/loader-utils'; | ||
/** Relative offset of local file header */ | ||
offset: number; | ||
offset: bigint; | ||
}; | ||
@@ -48,0 +48,0 @@ /** |
@@ -110,3 +110,3 @@ import { compareArrayBuffers, concatenateArrayBuffers } from '@loaders.gl/loader-utils'; | ||
optionsToZip64.offset = optionsToUse.offset; | ||
optionsToUse.offset = 0xffffffff; | ||
optionsToUse.offset = BigInt(0xffffffff); | ||
} | ||
@@ -121,3 +121,3 @@ if (optionsToUse.length >= 0xffffffff) { | ||
} | ||
const header = new DataView(new ArrayBuffer(46)); | ||
const header = new DataView(new ArrayBuffer(Number(CD_FILE_NAME_OFFSET))); | ||
for (const field of ZIP_HEADER_FIELDS) { | ||
@@ -124,0 +124,0 @@ var _ref, _optionsToUse, _field$name; |
@@ -11,4 +11,14 @@ import { FileProvider } from '@loaders.gl/loader-utils'; | ||
cdRecordsNumber: bigint; | ||
offsets: ZipEoCDRecordOffsets; | ||
}; | ||
/** | ||
* End of central directory offsets | ||
* according to https://en.wikipedia.org/wiki/ZIP_(file_format) | ||
*/ | ||
export type ZipEoCDRecordOffsets = { | ||
zipEoCDOffset: bigint; | ||
zip64EoCDOffset?: bigint; | ||
zip64EoCDLocatorOffset?: bigint; | ||
}; | ||
/** | ||
* Parses end of central directory record of zip file | ||
@@ -19,2 +29,11 @@ * @param file - FileProvider instance | ||
export declare const parseEoCDRecord: (file: FileProvider) => Promise<ZipEoCDRecord>; | ||
/** | ||
* updates EoCD record to add more files to the archieve | ||
* @param eocdBody buffer containing header | ||
* @param oldEoCDOffsets info read from EoCD record befor updating | ||
* @param newCDStartOffset CD start offset to be updated | ||
* @param eocdStartOffset EoCD start offset to be updated | ||
* @returns new EoCD header | ||
*/ | ||
export declare function updateEoCD(eocdBody: ArrayBuffer, oldEoCDOffsets: ZipEoCDRecordOffsets, newCDStartOffset: bigint, eocdStartOffset: bigint, newCDRecordsNumber: bigint): Promise<Uint8Array>; | ||
//# sourceMappingURL=end-of-central-directory.d.ts.map |
import { compareArrayBuffers } from '@loaders.gl/loader-utils'; | ||
import { searchFromTheEnd } from "./search-from-the-end.js"; | ||
import { setFieldToNumber } from "./zip64-info-generation.js"; | ||
const eoCDSignature = new Uint8Array([0x50, 0x4b, 0x05, 0x06]); | ||
@@ -7,5 +8,9 @@ const zip64EoCDLocatorSignature = new Uint8Array([0x50, 0x4b, 0x06, 0x07]); | ||
const CD_RECORDS_NUMBER_OFFSET = 8n; | ||
const CD_RECORDS_NUMBER_ON_DISC_OFFSET = 10n; | ||
const CD_CD_BYTE_SIZE_OFFSET = 12n; | ||
const CD_START_OFFSET_OFFSET = 16n; | ||
const ZIP64_EOCD_START_OFFSET_OFFSET = 8n; | ||
const ZIP64_CD_RECORDS_NUMBER_OFFSET = 24n; | ||
const ZIP64_CD_RECORDS_NUMBER_ON_DISC_OFFSET = 32n; | ||
const ZIP64_CD_CD_BYTE_SIZE_OFFSET = 40n; | ||
const ZIP64_CD_START_OFFSET_OFFSET = 48n; | ||
@@ -16,9 +21,7 @@ export const parseEoCDRecord = async file => { | ||
let cdStartOffset = BigInt(await file.getUint32(zipEoCDOffset + CD_START_OFFSET_OFFSET)); | ||
if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) { | ||
const zip64EoCDLocatorOffset = zipEoCDOffset - 20n; | ||
const magicBytes = await file.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n); | ||
if (!compareArrayBuffers(magicBytes, zip64EoCDLocatorSignature)) { | ||
throw new Error('zip64 EoCD locator not found'); | ||
} | ||
const zip64EoCDOffset = await file.getBigUint64(zip64EoCDLocatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET); | ||
let zip64EoCDLocatorOffset = zipEoCDOffset - 20n; | ||
let zip64EoCDOffset = 0n; | ||
const magicBytes = await file.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n); | ||
if (compareArrayBuffers(magicBytes, zip64EoCDLocatorSignature)) { | ||
zip64EoCDOffset = await file.getBigUint64(zip64EoCDLocatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET); | ||
const endOfCDMagicBytes = await file.slice(zip64EoCDOffset, zip64EoCDOffset + 4n); | ||
@@ -30,8 +33,39 @@ if (!compareArrayBuffers(endOfCDMagicBytes, zip64EoCDSignature.buffer)) { | ||
cdStartOffset = await file.getBigUint64(zip64EoCDOffset + ZIP64_CD_START_OFFSET_OFFSET); | ||
} else { | ||
zip64EoCDLocatorOffset = 0n; | ||
} | ||
return { | ||
cdRecordsNumber, | ||
cdStartOffset | ||
cdStartOffset, | ||
offsets: { | ||
zip64EoCDOffset, | ||
zip64EoCDLocatorOffset, | ||
zipEoCDOffset | ||
} | ||
}; | ||
}; | ||
export async function updateEoCD(eocdBody, oldEoCDOffsets, newCDStartOffset, eocdStartOffset, newCDRecordsNumber) { | ||
var _oldEoCDOffsets$zip; | ||
const eocd = new DataView(eocdBody); | ||
const classicEoCDOffset = oldEoCDOffsets.zipEoCDOffset - ((_oldEoCDOffsets$zip = oldEoCDOffsets.zip64EoCDOffset) !== null && _oldEoCDOffsets$zip !== void 0 ? _oldEoCDOffsets$zip : 0n); | ||
if (Number(newCDRecordsNumber) <= 0xffff) { | ||
setFieldToNumber(eocd, 2, classicEoCDOffset + CD_RECORDS_NUMBER_OFFSET, newCDRecordsNumber); | ||
setFieldToNumber(eocd, 2, classicEoCDOffset + CD_RECORDS_NUMBER_ON_DISC_OFFSET, newCDRecordsNumber); | ||
} | ||
if (eocdStartOffset - newCDStartOffset <= 0xffffffff) { | ||
setFieldToNumber(eocd, 4, classicEoCDOffset + CD_CD_BYTE_SIZE_OFFSET, eocdStartOffset - newCDStartOffset); | ||
} | ||
if (newCDStartOffset < 0xffffffff) { | ||
setFieldToNumber(eocd, 4, classicEoCDOffset + CD_START_OFFSET_OFFSET, newCDStartOffset); | ||
} | ||
if (oldEoCDOffsets.zip64EoCDLocatorOffset && oldEoCDOffsets.zip64EoCDOffset) { | ||
const locatorOffset = oldEoCDOffsets.zip64EoCDLocatorOffset - oldEoCDOffsets.zip64EoCDOffset; | ||
setFieldToNumber(eocd, 8, locatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET, eocdStartOffset); | ||
setFieldToNumber(eocd, 8, ZIP64_CD_START_OFFSET_OFFSET, newCDStartOffset); | ||
setFieldToNumber(eocd, 8, ZIP64_CD_RECORDS_NUMBER_OFFSET, newCDRecordsNumber); | ||
setFieldToNumber(eocd, 8, ZIP64_CD_RECORDS_NUMBER_ON_DISC_OFFSET, newCDRecordsNumber); | ||
setFieldToNumber(eocd, 8, ZIP64_CD_CD_BYTE_SIZE_OFFSET, eocdStartOffset - newCDStartOffset); | ||
} | ||
return new Uint8Array(eocd.buffer); | ||
} | ||
//# sourceMappingURL=end-of-central-directory.js.map |
@@ -22,4 +22,4 @@ export declare const signature: Uint8Array; | ||
*/ | ||
export declare function setFieldToNumber(header: DataView, fieldSize: number, fieldOffset: number, value: number | bigint): void; | ||
export declare function setFieldToNumber(header: DataView, fieldSize: number, fieldOffset: number | bigint, value: number | bigint): void; | ||
export {}; | ||
//# sourceMappingURL=zip64-info-generation.d.ts.map |
@@ -21,3 +21,3 @@ import { concatenateArrayBuffers } from '@loaders.gl/loader-utils'; | ||
export function setFieldToNumber(header, fieldSize, fieldOffset, value) { | ||
NUMBER_SETTERS[fieldSize](header, fieldOffset, value); | ||
NUMBER_SETTERS[fieldSize](header, Number(fieldOffset), value); | ||
} | ||
@@ -24,0 +24,0 @@ const NUMBER_SETTERS = { |
import JSZip from 'jszip'; | ||
const VERSION = typeof "4.1.0-alpha.3" !== 'undefined' ? "4.1.0-alpha.3" : 'latest'; | ||
const VERSION = typeof "4.1.0-alpha.4" !== 'undefined' ? "4.1.0-alpha.4" : 'latest'; | ||
export const ZipLoader = { | ||
@@ -4,0 +4,0 @@ id: 'zip', |
import JSZip from 'jszip'; | ||
const VERSION = typeof "4.1.0-alpha.3" !== 'undefined' ? "4.1.0-alpha.3" : 'latest'; | ||
const VERSION = typeof "4.1.0-alpha.4" !== 'undefined' ? "4.1.0-alpha.4" : 'latest'; | ||
export const ZipWriter = { | ||
@@ -4,0 +4,0 @@ name: 'Zip Archive', |
{ | ||
"name": "@loaders.gl/zip", | ||
"version": "4.1.0-alpha.3", | ||
"version": "4.1.0-alpha.4", | ||
"description": "Zip Archive Loader", | ||
@@ -41,9 +41,9 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/compression": "4.1.0-alpha.3", | ||
"@loaders.gl/crypto": "4.1.0-alpha.3", | ||
"@loaders.gl/loader-utils": "4.1.0-alpha.3", | ||
"@loaders.gl/compression": "4.1.0-alpha.4", | ||
"@loaders.gl/crypto": "4.1.0-alpha.4", | ||
"@loaders.gl/loader-utils": "4.1.0-alpha.4", | ||
"jszip": "^3.1.5", | ||
"md5": "^2.3.0" | ||
}, | ||
"gitHead": "b78075a7cb8d4ecd4aac84805ce74b8ceb400cf7" | ||
"gitHead": "b18ba1d63be704fd021e4470e8ab84175621e62d" | ||
} |
@@ -203,3 +203,3 @@ // loaders.gl | ||
/** Relative offset of local file header */ | ||
offset: number; | ||
offset: bigint; | ||
}; | ||
@@ -224,3 +224,3 @@ | ||
optionsToZip64.offset = optionsToUse.offset; | ||
optionsToUse.offset = 0xffffffff; | ||
optionsToUse.offset = BigInt(0xffffffff); | ||
} | ||
@@ -236,3 +236,3 @@ if (optionsToUse.length >= 0xffffffff) { | ||
} | ||
const header = new DataView(new ArrayBuffer(46)); | ||
const header = new DataView(new ArrayBuffer(Number(CD_FILE_NAME_OFFSET))); | ||
@@ -239,0 +239,0 @@ for (const field of ZIP_HEADER_FIELDS) { |
@@ -7,2 +7,3 @@ // loaders.gl | ||
import {ZipSignature, searchFromTheEnd} from './search-from-the-end'; | ||
import {setFieldToNumber} from './zip64-info-generation'; | ||
@@ -18,4 +19,16 @@ /** | ||
cdRecordsNumber: bigint; | ||
offsets: ZipEoCDRecordOffsets; | ||
}; | ||
/** | ||
* End of central directory offsets | ||
* according to https://en.wikipedia.org/wiki/ZIP_(file_format) | ||
*/ | ||
export type ZipEoCDRecordOffsets = { | ||
zipEoCDOffset: bigint; | ||
zip64EoCDOffset?: bigint; | ||
zip64EoCDLocatorOffset?: bigint; | ||
}; | ||
const eoCDSignature: ZipSignature = new Uint8Array([0x50, 0x4b, 0x05, 0x06]); | ||
@@ -27,5 +40,9 @@ const zip64EoCDLocatorSignature = new Uint8Array([0x50, 0x4b, 0x06, 0x07]); | ||
const CD_RECORDS_NUMBER_OFFSET = 8n; | ||
const CD_RECORDS_NUMBER_ON_DISC_OFFSET = 10n; | ||
const CD_CD_BYTE_SIZE_OFFSET = 12n; | ||
const CD_START_OFFSET_OFFSET = 16n; | ||
const ZIP64_EOCD_START_OFFSET_OFFSET = 8n; | ||
const ZIP64_CD_RECORDS_NUMBER_OFFSET = 24n; | ||
const ZIP64_CD_RECORDS_NUMBER_ON_DISC_OFFSET = 32n; | ||
const ZIP64_CD_CD_BYTE_SIZE_OFFSET = 40n; | ||
const ZIP64_CD_START_OFFSET_OFFSET = 48n; | ||
@@ -44,10 +61,8 @@ | ||
if (cdStartOffset === BigInt(0xffffffff) || cdRecordsNumber === BigInt(0xffffffff)) { | ||
const zip64EoCDLocatorOffset = zipEoCDOffset - 20n; | ||
let zip64EoCDLocatorOffset = zipEoCDOffset - 20n; | ||
let zip64EoCDOffset = 0n; | ||
const magicBytes = await file.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n); | ||
if (!compareArrayBuffers(magicBytes, zip64EoCDLocatorSignature)) { | ||
throw new Error('zip64 EoCD locator not found'); | ||
} | ||
const zip64EoCDOffset = await file.getBigUint64( | ||
const magicBytes = await file.slice(zip64EoCDLocatorOffset, zip64EoCDLocatorOffset + 4n); | ||
if (compareArrayBuffers(magicBytes, zip64EoCDLocatorSignature)) { | ||
zip64EoCDOffset = await file.getBigUint64( | ||
zip64EoCDLocatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET | ||
@@ -63,2 +78,4 @@ ); | ||
cdStartOffset = await file.getBigUint64(zip64EoCDOffset + ZIP64_CD_START_OFFSET_OFFSET); | ||
} else { | ||
zip64EoCDLocatorOffset = 0n; | ||
} | ||
@@ -68,4 +85,74 @@ | ||
cdRecordsNumber, | ||
cdStartOffset | ||
cdStartOffset, | ||
offsets: { | ||
zip64EoCDOffset, | ||
zip64EoCDLocatorOffset, | ||
zipEoCDOffset | ||
} | ||
}; | ||
}; | ||
/** | ||
* updates EoCD record to add more files to the archieve | ||
* @param eocdBody buffer containing header | ||
* @param oldEoCDOffsets info read from EoCD record befor updating | ||
* @param newCDStartOffset CD start offset to be updated | ||
* @param eocdStartOffset EoCD start offset to be updated | ||
* @returns new EoCD header | ||
*/ | ||
export async function updateEoCD( | ||
eocdBody: ArrayBuffer, | ||
oldEoCDOffsets: ZipEoCDRecordOffsets, | ||
newCDStartOffset: bigint, | ||
eocdStartOffset: bigint, | ||
newCDRecordsNumber: bigint | ||
): Promise<Uint8Array> { | ||
const eocd = new DataView(eocdBody); | ||
const classicEoCDOffset = oldEoCDOffsets.zipEoCDOffset - (oldEoCDOffsets.zip64EoCDOffset ?? 0n); | ||
// updating classic EoCD record with new CD records number in general and on disc | ||
if (Number(newCDRecordsNumber) <= 0xffff) { | ||
setFieldToNumber(eocd, 2, classicEoCDOffset + CD_RECORDS_NUMBER_OFFSET, newCDRecordsNumber); | ||
setFieldToNumber( | ||
eocd, | ||
2, | ||
classicEoCDOffset + CD_RECORDS_NUMBER_ON_DISC_OFFSET, | ||
newCDRecordsNumber | ||
); | ||
} | ||
// updating zip64 EoCD record with new size of CD | ||
if (eocdStartOffset - newCDStartOffset <= 0xffffffff) { | ||
setFieldToNumber( | ||
eocd, | ||
4, | ||
classicEoCDOffset + CD_CD_BYTE_SIZE_OFFSET, | ||
eocdStartOffset - newCDStartOffset | ||
); | ||
} | ||
// updating classic EoCD record with new CD start offset | ||
if (newCDStartOffset < 0xffffffff) { | ||
setFieldToNumber(eocd, 4, classicEoCDOffset + CD_START_OFFSET_OFFSET, newCDStartOffset); | ||
} | ||
// updating zip64 EoCD locator and record with new EoCD record start offset and cd records number | ||
if (oldEoCDOffsets.zip64EoCDLocatorOffset && oldEoCDOffsets.zip64EoCDOffset) { | ||
// updating zip64 EoCD locator with new EoCD record start offset | ||
const locatorOffset = oldEoCDOffsets.zip64EoCDLocatorOffset - oldEoCDOffsets.zip64EoCDOffset; | ||
setFieldToNumber(eocd, 8, locatorOffset + ZIP64_EOCD_START_OFFSET_OFFSET, eocdStartOffset); | ||
// updating zip64 EoCD record with new cd start offset | ||
setFieldToNumber(eocd, 8, ZIP64_CD_START_OFFSET_OFFSET, newCDStartOffset); | ||
// updating zip64 EoCD record with new cd records number | ||
setFieldToNumber(eocd, 8, ZIP64_CD_RECORDS_NUMBER_OFFSET, newCDRecordsNumber); | ||
setFieldToNumber(eocd, 8, ZIP64_CD_RECORDS_NUMBER_ON_DISC_OFFSET, newCDRecordsNumber); | ||
// updating zip64 EoCD record with new size of CD | ||
setFieldToNumber(eocd, 8, ZIP64_CD_CD_BYTE_SIZE_OFFSET, eocdStartOffset - newCDStartOffset); | ||
} | ||
return new Uint8Array(eocd.buffer); | ||
} |
@@ -56,6 +56,6 @@ import {concatenateArrayBuffers} from '@loaders.gl/loader-utils'; | ||
fieldSize: number, | ||
fieldOffset: number, | ||
fieldOffset: number | bigint, | ||
value: number | bigint | ||
): void { | ||
NUMBER_SETTERS[fieldSize](header, fieldOffset, value); | ||
NUMBER_SETTERS[fieldSize](header, Number(fieldOffset), value); | ||
} | ||
@@ -62,0 +62,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
595511
85
12514
+ Added@loaders.gl/compression@4.1.0-alpha.4(transitive)
+ Added@loaders.gl/crypto@4.1.0-alpha.4(transitive)
+ Added@loaders.gl/loader-utils@4.1.0-alpha.4(transitive)
+ Added@loaders.gl/worker-utils@4.1.0-alpha.4(transitive)
+ Added@types/node@22.12.0(transitive)
- Removed@loaders.gl/compression@4.1.0-alpha.3(transitive)
- Removed@loaders.gl/crypto@4.1.0-alpha.3(transitive)
- Removed@loaders.gl/loader-utils@4.1.0-alpha.3(transitive)
- Removed@loaders.gl/worker-utils@4.1.0-alpha.3(transitive)
- Removed@types/node@22.10.10(transitive)