Skip to content

Commit

Permalink
update lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed May 6, 2024
1 parent 970c71d commit 6354527
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 79 deletions.
71 changes: 51 additions & 20 deletions demos/lib/zip-fs-full.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator, Worker } = typeof globalThis !== 'undefined' ? globalThis : this || self;

var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
/*
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
Expand Down Expand Up @@ -1046,7 +1047,7 @@
bi_windup(); // align on byte boundary
last_eob_len = 8; // enough lookahead for inflate

if (header) {
{
put_short(len);
put_short(~len);
}
Expand All @@ -1061,7 +1062,7 @@
eof // true if this is the last block for a file
) {
send_bits((STORED_BLOCK << 1) + (eof ? 1 : 0), 3); // send block type
copy_block(buf, stored_len, true); // with header
copy_block(buf, stored_len); // with header
}

// Determine the best encoding for the current block: dynamic trees, static
Expand Down Expand Up @@ -4331,6 +4332,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


class StreamAdapter {

constructor(Codec) {
Expand Down Expand Up @@ -4381,6 +4383,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const MINIMUM_CHUNK_SIZE = 64;
let maxWorkers = 2;
try {
Expand Down Expand Up @@ -4495,6 +4498,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


function getMimeType$1() {
return "application/octet-stream";
}
Expand Down Expand Up @@ -4527,6 +4531,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const table$1 = {
"application": {
"andrew-inset": "ez",
Expand Down Expand Up @@ -6218,6 +6223,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


class Crc32Stream extends TransformStream {

constructor() {
Expand Down Expand Up @@ -6267,6 +6273,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


function encodeText(value) {
if (typeof TextEncoder == UNDEFINED_TYPE) {
value = unescape(encodeURIComponent(value));
Expand Down Expand Up @@ -7128,6 +7135,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE;

const ERR_INVALID_PASSWORD = "Invalid password";
Expand Down Expand Up @@ -7170,6 +7178,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const BLOCK_LENGTH = 16;
const RAW_FORMAT = "raw";
const PBKDF2_ALGORITHM = { name: "PBKDF2" };
Expand Down Expand Up @@ -7473,6 +7482,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const HEADER_LENGTH = 12;

class ZipCryptoDecryptionStream extends TransformStream {
Expand Down Expand Up @@ -7620,6 +7630,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const COMPRESSION_FORMAT = "deflate-raw";

class DeflateStream extends TransformStream {
Expand Down Expand Up @@ -7760,6 +7771,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const MESSAGE_EVENT_TYPE = "message";
const MESSAGE_START = "start";
const MESSAGE_PULL = "pull";
Expand Down Expand Up @@ -7881,6 +7893,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


// deno-lint-ignore valid-typeof
let WEB_WORKERS_SUPPORTED = typeof Worker != UNDEFINED_TYPE;

Expand Down Expand Up @@ -8209,6 +8222,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


let pool = [];
const pendingRequests = [];

Expand Down Expand Up @@ -8372,6 +8386,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const ERR_HTTP_STATUS = "HTTP error ";
const ERR_HTTP_RANGE = "HTTP Range not supported";
const ERR_ITERATOR_COMPLETED_TOO_SOON = "Writer iterator completed too soon";
Expand Down Expand Up @@ -9132,6 +9147,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


function decodeText(value, encoding) {
if (encoding && encoding.trim().toLowerCase() == "cp437") {
return decodeCP437(value);
Expand Down Expand Up @@ -9233,6 +9249,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const ERR_BAD_FORMAT = "File format is not recognized";
const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
Expand Down Expand Up @@ -9411,10 +9428,16 @@
rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
});
const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
const [filename, comment] = await Promise.all([
decode(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
decode(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
]);
const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
let filename = decode(rawFilename, rawFilenameEncoding);
if (filename === UNDEFINED_VALUE) {
filename = decodeText(rawFilename, rawFilenameEncoding);
}
let comment = decode(rawComment, rawCommentEncoding);
if (comment === UNDEFINED_VALUE) {
comment = decodeText(rawComment, rawCommentEncoding);
}
Object.assign(fileEntry, {
rawComment,
filename,
Expand Down Expand Up @@ -9488,7 +9511,7 @@
}
}

class ZipEntry$1 {
let ZipEntry$1 = class ZipEntry {

constructor(reader, config, options) {
Object.assign(this, {
Expand Down Expand Up @@ -9602,7 +9625,7 @@
}
return checkPasswordOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable;
}
}
};

function readCommonHeader(directory, dataView, offset) {
const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
Expand Down Expand Up @@ -9896,6 +9919,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


const ERR_DUPLICATED_NAME = "File already exists";
const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
Expand Down Expand Up @@ -10018,12 +10042,18 @@
options.directory = name.endsWith(DIRECTORY_SIGNATURE);
}
const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
const rawFilename = encode(name);
let rawFilename = encode(name);
if (rawFilename === UNDEFINED_VALUE) {
rawFilename = encodeText(name);
}
if (getLength(rawFilename) > MAX_16_BITS) {
throw new Error(ERR_INVALID_ENTRY_NAME);
}
const comment = options.comment || "";
const rawComment = encode(comment);
let rawComment = encode(comment);
if (rawComment === UNDEFINED_VALUE) {
rawComment = encodeText(comment);
}
if (getLength(rawComment) > MAX_16_BITS) {
throw new Error(ERR_INVALID_ENTRY_COMMENT);
}
Expand Down Expand Up @@ -10089,19 +10119,19 @@
dataDescriptor = true;
if (zip64 || zip64 === UNDEFINED_VALUE) {
zip64 = true;
uncompressedSize = maximumCompressedSize = MAX_32_BITS;
uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
}
} else {
uncompressedSize = reader.size;
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
}
}
const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS;
const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
const supportZip64SplitFile = getOptionValue(zipWriter, options, "supportZip64SplitFile", true);
const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS;
const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
if (zip64 === false || !keepOrder) {
throw new Error(ERR_UNSUPPORTED_FORMAT);
Expand Down Expand Up @@ -10244,7 +10274,7 @@
fileEntry.offset = zipWriter.offset - diskOffset;
if (fileEntry.zip64) {
setZip64ExtraInfo(fileEntry, options);
} else if (fileEntry.offset >= MAX_32_BITS) {
} else if (fileEntry.offset > MAX_32_BITS) {
throw new Error(ERR_UNSUPPORTED_FORMAT);
}
zipWriter.offset += fileEntry.size;
Expand Down Expand Up @@ -10861,7 +10891,7 @@
lastDiskNumber++;
}
let zip64 = getOptionValue(zipWriter, options, "zip64");
if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
if (zip64 === false) {
throw new Error(ERR_UNSUPPORTED_FORMAT);
} else {
Expand Down Expand Up @@ -11000,6 +11030,7 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


class ZipEntry {

constructor(fs, name, params, parent) {
Expand Down Expand Up @@ -11837,9 +11868,10 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


let baseURL;
try {
baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('zip-fs-full.js', document.baseURI).href));
baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('zip-fs-full.js', document.baseURI).href));
} catch (_error) {
// ignored
}
Expand All @@ -11848,6 +11880,7 @@

/// <reference types="./index.d.ts" />


configure({ Deflate: ZipDeflate, Inflate: ZipInflate });

exports.BlobReader = BlobReader;
Expand Down Expand Up @@ -11899,6 +11932,4 @@
exports.initShimAsyncCodec = initShimAsyncCodec;
exports.terminateWorkers = terminateWorkers;

Object.defineProperty(exports, '__esModule', { value: true });

}));
2 changes: 1 addition & 1 deletion demos/lib/zip-fs-full.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6354527

Please sign in to comment.