@loaders.gl/zip
Advanced tools
Comparing version 4.1.0-alpha.4 to 4.1.0-alpha.5
@@ -14,2 +14,8 @@ import { FileProvider } from '@loaders.gl/loader-utils'; | ||
export declare function makeHashTableFromZipHeaders(fileProvider: FileProvider): Promise<Record<string, bigint>>; | ||
/** | ||
* creates hash file that later can be added to the SLPK archive | ||
* @param fileProvider SLPK archive where we need to add hash file | ||
* @returns ArrayBuffer containing hash file | ||
*/ | ||
export declare function composeHashFile(fileProvider: FileProvider): Promise<ArrayBuffer>; | ||
//# sourceMappingURL=hash-file-utility.d.ts.map |
import { MD5Hash } from '@loaders.gl/crypto'; | ||
import { concatenateArrayBuffers } from '@loaders.gl/loader-utils'; | ||
import { makeZipCDHeaderIterator } from "./parse-zip/cd-file-header.js"; | ||
@@ -29,2 +30,23 @@ export function parseHashTable(arrayBuffer) { | ||
} | ||
export async function composeHashFile(fileProvider) { | ||
const hashArray = await makeHashTableFromZipHeaders(fileProvider); | ||
const bufferArray = Object.entries(hashArray).map(_ref => { | ||
let [key, value] = _ref; | ||
return concatenateArrayBuffers(hexStringToBuffer(key), bigintToBuffer(value)); | ||
}).sort(compareHashes); | ||
return concatenateArrayBuffers(...bufferArray); | ||
} | ||
function compareHashes(arrA, arrB) { | ||
const a = new BigUint64Array(arrA); | ||
const b = new BigUint64Array(arrB); | ||
return Number(a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]); | ||
} | ||
function hexStringToBuffer(str) { | ||
var _str$match; | ||
const byteArray = (_str$match = str.match(/../g)) === null || _str$match === void 0 ? void 0 : _str$match.map(h => parseInt(h, 16)); | ||
return new Uint8Array(byteArray !== null && byteArray !== void 0 ? byteArray : new Array(16)).buffer; | ||
} | ||
function bigintToBuffer(n) { | ||
return new BigUint64Array([n]).buffer; | ||
} | ||
//# sourceMappingURL=hash-file-utility.js.map |
@@ -8,4 +8,5 @@ export { ZipLoader } from './zip-loader'; | ||
export { searchFromTheEnd } from './parse-zip/search-from-the-end'; | ||
export { parseHashTable, makeHashTableFromZipHeaders } from './hash-file-utility'; | ||
export { addOneFile } from './parse-zip/zip-compozition'; | ||
export { parseHashTable, makeHashTableFromZipHeaders, composeHashFile } from './hash-file-utility'; | ||
export { ZipFileSystem } from './filesystems/zip-filesystem'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -8,4 +8,5 @@ export { ZipLoader } from "./zip-loader.js"; | ||
export { searchFromTheEnd } from "./parse-zip/search-from-the-end.js"; | ||
export { parseHashTable, makeHashTableFromZipHeaders } from "./hash-file-utility.js"; | ||
export { addOneFile } from "./parse-zip/zip-compozition.js"; | ||
export { parseHashTable, makeHashTableFromZipHeaders, composeHashFile } from "./hash-file-utility.js"; | ||
export { ZipFileSystem } from "./filesystems/zip-filesystem.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -45,5 +45,4 @@ import { compareArrayBuffers } from '@loaders.gl/loader-utils'; | ||
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); | ||
const classicEoCDOffset = oldEoCDOffsets.zip64EoCDOffset ? oldEoCDOffsets.zipEoCDOffset - oldEoCDOffsets.zip64EoCDOffset : 0n; | ||
if (Number(newCDRecordsNumber) <= 0xffff) { | ||
@@ -50,0 +49,0 @@ setFieldToNumber(eocd, 2, classicEoCDOffset + CD_RECORDS_NUMBER_OFFSET, newCDRecordsNumber); |
import JSZip from 'jszip'; | ||
const VERSION = typeof "4.1.0-alpha.4" !== 'undefined' ? "4.1.0-alpha.4" : 'latest'; | ||
const VERSION = typeof "4.1.0-alpha.5" !== 'undefined' ? "4.1.0-alpha.5" : 'latest'; | ||
export const ZipLoader = { | ||
@@ -4,0 +4,0 @@ id: 'zip', |
import JSZip from 'jszip'; | ||
const VERSION = typeof "4.1.0-alpha.4" !== 'undefined' ? "4.1.0-alpha.4" : 'latest'; | ||
const VERSION = typeof "4.1.0-alpha.5" !== 'undefined' ? "4.1.0-alpha.5" : 'latest'; | ||
export const ZipWriter = { | ||
@@ -4,0 +4,0 @@ name: 'Zip Archive', |
{ | ||
"name": "@loaders.gl/zip", | ||
"version": "4.1.0-alpha.4", | ||
"version": "4.1.0-alpha.5", | ||
"description": "Zip Archive Loader", | ||
@@ -41,9 +41,9 @@ "license": "MIT", | ||
"dependencies": { | ||
"@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", | ||
"@loaders.gl/compression": "4.1.0-alpha.5", | ||
"@loaders.gl/crypto": "4.1.0-alpha.5", | ||
"@loaders.gl/loader-utils": "4.1.0-alpha.5", | ||
"jszip": "^3.1.5", | ||
"md5": "^2.3.0" | ||
}, | ||
"gitHead": "b18ba1d63be704fd021e4470e8ab84175621e62d" | ||
"gitHead": "3250842d8cc0fc8b76a575168c1fd57e5a66b6ba" | ||
} |
@@ -6,3 +6,3 @@ // loaders.gl | ||
import {MD5Hash} from '@loaders.gl/crypto'; | ||
import {FileProvider} from '@loaders.gl/loader-utils'; | ||
import {FileProvider, concatenateArrayBuffers} from '@loaders.gl/loader-utils'; | ||
import {makeZipCDHeaderIterator} from './parse-zip/cd-file-header'; | ||
@@ -59,1 +59,46 @@ | ||
} | ||
/** | ||
* creates hash file that later can be added to the SLPK archive | ||
* @param fileProvider SLPK archive where we need to add hash file | ||
* @returns ArrayBuffer containing hash file | ||
*/ | ||
export async function composeHashFile(fileProvider: FileProvider): Promise<ArrayBuffer> { | ||
const hashArray = await makeHashTableFromZipHeaders(fileProvider); | ||
const bufferArray = Object.entries(hashArray) | ||
.map(([key, value]) => concatenateArrayBuffers(hexStringToBuffer(key), bigintToBuffer(value))) | ||
.sort(compareHashes); | ||
return concatenateArrayBuffers(...bufferArray); | ||
} | ||
/** | ||
* Function to compare md5 hashes according to https://github.com/Esri/i3s-spec/blob/master/docs/2.0/slpk_hashtable.pcsl.md | ||
* @param arrA first hash to compare | ||
* @param arrB second hash to compare | ||
* @returns 0 if equal, negative number if a<b, pozitive if a>b | ||
*/ | ||
function compareHashes(arrA: ArrayBuffer, arrB: ArrayBuffer): number { | ||
const a = new BigUint64Array(arrA); | ||
const b = new BigUint64Array(arrB); | ||
return Number(a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]); | ||
} | ||
/** | ||
* converts hex string to buffer | ||
* @param str hex string to convert | ||
* @returns conversion result | ||
*/ | ||
function hexStringToBuffer(str: string): ArrayBuffer { | ||
const byteArray = str.match(/../g)?.map((h) => parseInt(h, 16)); | ||
return new Uint8Array(byteArray ?? new Array(16)).buffer; | ||
} | ||
/** | ||
* converts bigint to buffer | ||
* @param n bigint to convert | ||
* @returns convertion result | ||
*/ | ||
function bigintToBuffer(n: bigint): ArrayBuffer { | ||
return new BigUint64Array([n]).buffer; | ||
} |
@@ -22,6 +22,7 @@ // loaders.gl | ||
export {searchFromTheEnd} from './parse-zip/search-from-the-end'; | ||
export {addOneFile} from './parse-zip/zip-compozition'; | ||
// export type {HashElement} from './hash-file-utility'; | ||
export {parseHashTable, makeHashTableFromZipHeaders} from './hash-file-utility'; | ||
export {parseHashTable, makeHashTableFromZipHeaders, composeHashFile} from './hash-file-utility'; | ||
export {ZipFileSystem} from './filesystems/zip-filesystem'; |
@@ -106,3 +106,5 @@ // loaders.gl | ||
const classicEoCDOffset = oldEoCDOffsets.zipEoCDOffset - (oldEoCDOffsets.zip64EoCDOffset ?? 0n); | ||
const classicEoCDOffset = oldEoCDOffsets.zip64EoCDOffset | ||
? oldEoCDOffsets.zipEoCDOffset - oldEoCDOffsets.zip64EoCDOffset | ||
: 0n; | ||
@@ -109,0 +111,0 @@ // updating classic EoCD record with new CD records number in general and on disc |
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
Sorry, the diff of this file is not supported yet
616214
12859
+ Added@loaders.gl/compression@4.1.0-alpha.5(transitive)
+ Added@loaders.gl/crypto@4.1.0-alpha.5(transitive)
+ Added@loaders.gl/loader-utils@4.1.0-alpha.5(transitive)
+ Added@loaders.gl/worker-utils@4.1.0-alpha.5(transitive)
+ Added@types/node@22.12.0(transitive)
- Removed@loaders.gl/compression@4.1.0-alpha.4(transitive)
- Removed@loaders.gl/crypto@4.1.0-alpha.4(transitive)
- Removed@loaders.gl/loader-utils@4.1.0-alpha.4(transitive)
- Removed@loaders.gl/worker-utils@4.1.0-alpha.4(transitive)
- Removed@types/node@22.10.10(transitive)