@loaders.gl/zip
Advanced tools
Comparing version 4.0.4 to 4.1.0-alpha.1
export { ZipLoader } from './zip-loader'; | ||
export { ZipWriter } from './zip-writer'; | ||
export { TarBuilder } from './tar-builder'; | ||
export { parseZipCDFileHeader, makeZipCDHeaderIterator, signature as cdSignature } from './parse-zip/cd-file-header'; | ||
export { parseZipCDFileHeader, makeZipCDHeaderIterator, signature as CD_HEADER_SIGNATURE, generateCDHeader } from './parse-zip/cd-file-header'; | ||
export { parseZipLocalFileHeader, signature as localHeaderSignature } from './parse-zip/local-file-header'; | ||
@@ -6,0 +6,0 @@ export { parseEoCDRecord } from './parse-zip/end-of-central-directory'; |
export { ZipLoader } from "./zip-loader.js"; | ||
export { ZipWriter } from "./zip-writer.js"; | ||
export { TarBuilder } from "./tar-builder.js"; | ||
export { parseZipCDFileHeader, makeZipCDHeaderIterator, signature as cdSignature } from "./parse-zip/cd-file-header.js"; | ||
export { parseZipCDFileHeader, makeZipCDHeaderIterator, signature as CD_HEADER_SIGNATURE, generateCDHeader } from "./parse-zip/cd-file-header.js"; | ||
export { parseZipLocalFileHeader, signature as localHeaderSignature } from "./parse-zip/local-file-header.js"; | ||
@@ -6,0 +6,0 @@ export { parseEoCDRecord } from "./parse-zip/end-of-central-directory.js"; |
@@ -36,2 +36,20 @@ import { FileProvider } from '@loaders.gl/loader-utils'; | ||
export declare function makeZipCDHeaderIterator(fileProvider: FileProvider): AsyncIterable<ZipCDFileHeader>; | ||
/** info that can be placed into cd header */ | ||
type GenerateCDOptions = { | ||
/** CRC-32 of uncompressed data */ | ||
crc32: number; | ||
/** File name */ | ||
fileName: string; | ||
/** File size */ | ||
length: number; | ||
/** Relative offset of local file header */ | ||
offset: number; | ||
}; | ||
/** | ||
* generates cd header for the file | ||
* @param options info that can be placed into cd header | ||
* @returns buffer with header | ||
*/ | ||
export declare function generateCDHeader(options: GenerateCDOptions): ArrayBuffer; | ||
export {}; | ||
//# sourceMappingURL=cd-file-header.d.ts.map |
@@ -1,3 +0,4 @@ | ||
import { compareArrayBuffers } from '@loaders.gl/loader-utils'; | ||
import { compareArrayBuffers, concatenateArrayBuffers } from '@loaders.gl/loader-utils'; | ||
import { parseEoCDRecord } from "./end-of-central-directory.js"; | ||
import { createZip64Info, NUMBER_SETTERS } from "./zip64-info-generation.js"; | ||
const CD_COMPRESSED_SIZE_OFFSET = 20n; | ||
@@ -99,2 +100,101 @@ const CD_UNCOMPRESSED_SIZE_OFFSET = 24n; | ||
}; | ||
export function generateCDHeader(options) { | ||
const optionsToUse = { | ||
...options, | ||
fnlength: options.fileName.length, | ||
extraLength: 0 | ||
}; | ||
let zip64header = new ArrayBuffer(0); | ||
const optionsToZip64 = {}; | ||
if (optionsToUse.offset >= 0xffffffff) { | ||
optionsToZip64.offset = optionsToUse.offset; | ||
optionsToUse.offset = 0xffffffff; | ||
} | ||
if (optionsToUse.length >= 0xffffffff) { | ||
optionsToZip64.size = optionsToUse.length; | ||
optionsToUse.length = 0xffffffff; | ||
} | ||
if (Object.keys(optionsToZip64).length) { | ||
zip64header = createZip64Info(optionsToZip64); | ||
optionsToUse.extraLength = zip64header.byteLength; | ||
} | ||
const header = new DataView(new ArrayBuffer(46)); | ||
for (const field of ZIP_HEADER_FIELDS) { | ||
var _ref, _optionsToUse, _field$name; | ||
NUMBER_SETTERS[field.size](header, field.offset, (_ref = (_optionsToUse = optionsToUse[(_field$name = field.name) !== null && _field$name !== void 0 ? _field$name : '']) !== null && _optionsToUse !== void 0 ? _optionsToUse : field.default) !== null && _ref !== void 0 ? _ref : 0); | ||
} | ||
const encodedName = new TextEncoder().encode(optionsToUse.fileName); | ||
const resHeader = concatenateArrayBuffers(header.buffer, encodedName, zip64header); | ||
return resHeader; | ||
} | ||
const ZIP_HEADER_FIELDS = [{ | ||
offset: 0, | ||
size: 4, | ||
default: new DataView(signature.buffer).getUint32(0, true) | ||
}, { | ||
offset: 4, | ||
size: 2, | ||
default: 45 | ||
}, { | ||
offset: 6, | ||
size: 2, | ||
default: 45 | ||
}, { | ||
offset: 8, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 10, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 12, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 14, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 16, | ||
size: 4, | ||
name: 'crc32' | ||
}, { | ||
offset: 20, | ||
size: 4, | ||
name: 'length' | ||
}, { | ||
offset: 24, | ||
size: 4, | ||
name: 'length' | ||
}, { | ||
offset: 28, | ||
size: 2, | ||
name: 'fnlength' | ||
}, { | ||
offset: 30, | ||
size: 2, | ||
default: 0, | ||
name: 'extraLength' | ||
}, { | ||
offset: 32, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 34, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 36, | ||
size: 2, | ||
default: 0 | ||
}, { | ||
offset: 38, | ||
size: 4, | ||
default: 0 | ||
}, { | ||
offset: 42, | ||
size: 4, | ||
name: 'offset' | ||
}]; | ||
//# sourceMappingURL=cd-file-header.js.map |
{ | ||
"name": "@loaders.gl/zip", | ||
"version": "4.0.4", | ||
"version": "4.1.0-alpha.1", | ||
"description": "Zip Archive Loader", | ||
@@ -41,9 +41,9 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/compression": "4.0.4", | ||
"@loaders.gl/crypto": "4.0.4", | ||
"@loaders.gl/loader-utils": "4.0.4", | ||
"@loaders.gl/compression": "4.1.0-alpha.1", | ||
"@loaders.gl/crypto": "4.1.0-alpha.1", | ||
"@loaders.gl/loader-utils": "4.1.0-alpha.1", | ||
"jszip": "^3.1.5", | ||
"md5": "^2.3.0" | ||
}, | ||
"gitHead": "4dc810fa04bb400f4aedfef98a83c7ef882ed3d7" | ||
"gitHead": "6a4d3da93d45115ad99861474a43c3f4a0b280a7" | ||
} |
@@ -11,3 +11,4 @@ // loaders.gl, MIT license | ||
makeZipCDHeaderIterator, | ||
signature as cdSignature | ||
signature as CD_HEADER_SIGNATURE, | ||
generateCDHeader | ||
} from './parse-zip/cd-file-header'; | ||
@@ -14,0 +15,0 @@ export { |
// loaders.gl, MIT license | ||
// Copyright (c) vis.gl contributors | ||
import {FileProvider, compareArrayBuffers} from '@loaders.gl/loader-utils'; | ||
import {FileProvider, compareArrayBuffers, concatenateArrayBuffers} from '@loaders.gl/loader-utils'; | ||
import {parseEoCDRecord} from './end-of-central-directory'; | ||
import {ZipSignature} from './search-from-the-end'; | ||
import {createZip64Info, NUMBER_SETTERS} from './zip64-info-generation'; | ||
@@ -191,1 +192,181 @@ /** | ||
}; | ||
/** info that can be placed into cd header */ | ||
type GenerateCDOptions = { | ||
/** CRC-32 of uncompressed data */ | ||
crc32: number; | ||
/** File name */ | ||
fileName: string; | ||
/** File size */ | ||
length: number; | ||
/** Relative offset of local file header */ | ||
offset: number; | ||
}; | ||
/** | ||
* generates cd header for the file | ||
* @param options info that can be placed into cd header | ||
* @returns buffer with header | ||
*/ | ||
export function generateCDHeader(options: GenerateCDOptions): ArrayBuffer { | ||
const optionsToUse = { | ||
...options, | ||
fnlength: options.fileName.length, | ||
extraLength: 0 | ||
}; | ||
let zip64header: ArrayBuffer = new ArrayBuffer(0); | ||
const optionsToZip64: any = {}; | ||
if (optionsToUse.offset >= 0xffffffff) { | ||
optionsToZip64.offset = optionsToUse.offset; | ||
optionsToUse.offset = 0xffffffff; | ||
} | ||
if (optionsToUse.length >= 0xffffffff) { | ||
optionsToZip64.size = optionsToUse.length; | ||
optionsToUse.length = 0xffffffff; | ||
} | ||
if (Object.keys(optionsToZip64).length) { | ||
zip64header = createZip64Info(optionsToZip64); | ||
optionsToUse.extraLength = zip64header.byteLength; | ||
} | ||
const header = new DataView(new ArrayBuffer(46)); | ||
for (const field of ZIP_HEADER_FIELDS) { | ||
NUMBER_SETTERS[field.size]( | ||
header, | ||
field.offset, | ||
optionsToUse[field.name ?? ''] ?? field.default ?? 0 | ||
); | ||
} | ||
const encodedName = new TextEncoder().encode(optionsToUse.fileName); | ||
const resHeader = concatenateArrayBuffers(header.buffer, encodedName, zip64header); | ||
return resHeader; | ||
} | ||
/** Fields map */ | ||
const ZIP_HEADER_FIELDS = [ | ||
// Central directory file header signature = 0x02014b50 | ||
{ | ||
offset: 0, | ||
size: 4, | ||
default: new DataView(signature.buffer).getUint32(0, true) | ||
}, | ||
// Version made by | ||
{ | ||
offset: 4, | ||
size: 2, | ||
default: 45 | ||
}, | ||
// Version needed to extract (minimum) | ||
{ | ||
offset: 6, | ||
size: 2, | ||
default: 45 | ||
}, | ||
// General purpose bit flag | ||
{ | ||
offset: 8, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// Compression method | ||
{ | ||
offset: 10, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// File last modification time | ||
{ | ||
offset: 12, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// File last modification date | ||
{ | ||
offset: 14, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// CRC-32 of uncompressed data | ||
{ | ||
offset: 16, | ||
size: 4, | ||
name: 'crc32' | ||
}, | ||
// Compressed size (or 0xffffffff for ZIP64) | ||
{ | ||
offset: 20, | ||
size: 4, | ||
name: 'length' | ||
}, | ||
// Uncompressed size (or 0xffffffff for ZIP64) | ||
{ | ||
offset: 24, | ||
size: 4, | ||
name: 'length' | ||
}, | ||
// File name length (n) | ||
{ | ||
offset: 28, | ||
size: 2, | ||
name: 'fnlength' | ||
}, | ||
// Extra field length (m) | ||
{ | ||
offset: 30, | ||
size: 2, | ||
default: 0, | ||
name: 'extraLength' | ||
}, | ||
// File comment length (k) | ||
{ | ||
offset: 32, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// Disk number where file starts (or 0xffff for ZIP64) | ||
{ | ||
offset: 34, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// Internal file attributes | ||
{ | ||
offset: 36, | ||
size: 2, | ||
default: 0 | ||
}, | ||
// External file attributes | ||
{ | ||
offset: 38, | ||
size: 4, | ||
default: 0 | ||
}, | ||
// Relative offset of local file header | ||
{ | ||
offset: 42, | ||
size: 4, | ||
name: 'offset' | ||
} | ||
]; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
552466
80
11756
2
+ Added@loaders.gl/compression@4.1.0-alpha.1(transitive)
+ Added@loaders.gl/crypto@4.1.0-alpha.1(transitive)
+ Added@loaders.gl/loader-utils@4.1.0-alpha.1(transitive)
+ Added@loaders.gl/worker-utils@4.1.0-alpha.1(transitive)
- Removed@loaders.gl/compression@4.0.4(transitive)
- Removed@loaders.gl/crypto@4.0.4(transitive)
- Removed@loaders.gl/loader-utils@4.0.4(transitive)
- Removed@loaders.gl/worker-utils@4.0.4(transitive)