### onstart Event Handler Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipWriterAddDataOptions.md The `onstart` function is an optional callback that gets executed when a compression or decompression operation begins. It receives the total number of bytes as an argument and can optionally return a Promise. ```APIDOC ## onstart() ### Description The function called when starting compression/decompression. ### Method `optional` ### Parameters #### Path Parameters - **total** (number) - Required - The total number of bytes. ### Returns `void` | `Promise`<`void`> An empty promise or `undefined`. ``` -------------------------------- ### Create, Add, Export, Import, and Read Zip Archive Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/FS.md This example demonstrates creating a zip filesystem, adding a text file as a Blob, exporting it to a Blob, importing it back, and then reading the content of the first entry. Ensure zip.js is properly imported and initialized. ```javascript const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."; const FILENAME = "lorem.txt"; const BLOB = new Blob([TEXT_CONTENT], { type: zip.getMimeType(FILENAME) }); let zipFs = new zip.fs.FS(); zipFs.addBlob("lorem.txt", BLOB); const zippedBlob = await zipFs.exportBlob(); zipFs = new zip.fs.FS(); await zipFs.importBlob(zippedBlob); const firstEntry = zipFs.children[0]; const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name)); ``` -------------------------------- ### Create a Zip File with ZipWriter Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/ZipWriter.md This example demonstrates how to create a zip file containing a compressed text file. It uses BlobWriter to store the zip in a Blob and TextReader to read the string content. ```javascript // use a BlobWriter to store with a ZipWriter the zip into a Blob object const blobWriter = new zip.BlobWriter("application/zip"); const writer = new zip.ZipWriter(blobWriter); // use a TextReader to read the String to add await writer.add("filename.txt", new zip.TextReader("test!")); // close the ZipReader await writer.close(); // get the zip file as a Blob const blob = await blobWriter.getData(); ``` -------------------------------- ### Create and Read Encrypted Zip Archives with AES Source: https://context7.com/gildas-lormeau/zip.js/llms.txt Encrypt zip archives using AES-256 (recommended) or AES-128/192 by providing a password and encryption strength. This example also shows how to decrypt entries and check passwords without full extraction. ```javascript import { ZipWriter, ZipReader, BlobWriter, BlobReader, TextReader, TextWriter } from "@zip.js/zip.js"; // Create encrypted zip with AES-256 (recommended) const encryptedWriter = new ZipWriter(new BlobWriter(), { password: "strongPassword123", encryptionStrength: 3 // 1=AES-128, 2=AES-192, 3=AES-256 }); await encryptedWriter.add("secret.txt", new TextReader("Confidential data")); await encryptedWriter.add("private.txt", new TextReader("Private information")); const encryptedZip = await encryptedWriter.close(); // Per-entry encryption with different passwords const mixedWriter = new ZipWriter(new BlobWriter()); await mixedWriter.add("public.txt", new TextReader("Public data")); await mixedWriter.add("secret1.txt", new TextReader("Secret 1"), { password: "password1", encryptionStrength: 3 }); await mixedWriter.add("secret2.txt", new TextReader("Secret 2"), { password: "password2", encryptionStrength: 3 }); const mixedZip = await mixedWriter.close(); // Read encrypted zip const reader = new ZipReader(new BlobReader(encryptedZip)); const entries = await reader.getEntries(); for (const entry of entries) { if (entry.encrypted && !entry.directory) { try { const content = await entry.getData(new TextWriter(), { password: "strongPassword123" }); console.log(`Decrypted ${entry.filename}: ${content}`); } catch (error) { console.error(`Failed to decrypt ${entry.filename}:`, error.message); } } } // Check password without extracting const [testEntry] = entries.filter(e => e.encrypted && !e.directory); try { await testEntry.getData(new TextWriter(), { password: "wrongPassword", checkPasswordOnly: true }); console.log("Password is correct"); } catch { console.log("Password is incorrect"); } await reader.close(); // Legacy ZipCrypto (less secure, for compatibility only) const legacyWriter = new ZipWriter(new BlobWriter(), { password: "legacyPassword", zipCrypto: true // Use legacy encryption }); await legacyWriter.add("legacy.txt", new TextReader("Legacy encrypted")); await legacyWriter.close(); ``` -------------------------------- ### Reader Class Overview Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/Reader.md Provides an overview of the Reader class, its purpose, and an example of a custom implementation. ```APIDOC ## Class: Reader Defined in: [index.d.ts:373](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L373) Represents an instance used to read unknown type of data. ### Example Here is an example of custom Reader class used to read binary strings: ```javascript class BinaryStringReader extends Reader { constructor(binaryString) { super(); this.binaryString = binaryString; } init() { super.init(); this.size = this.binaryString.length; } readUint8Array(offset, length) { const result = new Uint8Array(length); for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) { result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF; } return result; } } ``` ### Extended by - [`TextReader`](TextReader.md) - [`BlobReader`](BlobReader.md) - [`Data64URIReader`](Data64URIReader.md) - [`Uint8ArrayReader`](Uint8ArrayReader.md) - [`SplitDataReader`](SplitDataReader.md) - [`HttpReader`](HttpReader.md) ### Type Parameters #### Type `Type` ### Implements - [`Initializable`](../interfaces/Initializable.md) - [`ReadableReader`](../interfaces/ReadableReader.md) ``` -------------------------------- ### Hello World with zip.js Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/README.md Demonstrates basic zip file creation and extraction using Blob and Text readers/writers. ```js import { BlobReader, BlobWriter, TextReader, TextWriter, ZipReader, ZipWriter } from "@zip-js/zip-js"; // Prefix "@zip-js/zip-js" with "jsr:" for Deno // ---- // Write the zip file // ---- // Creates a BlobWriter object where the zip content will be written. const zipFileWriter = new BlobWriter(); // Creates a TextReader object storing the text of the entry to add in the zip // (i.e. "Hello world!"). const helloWorldReader = new TextReader("Hello world!"); // Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry // "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and // closes the writer. const zipWriter = new ZipWriter(zipFileWriter); await zipWriter.add("hello.txt", helloWorldReader); await zipWriter.close(); // Retrieves the Blob object containing the zip content into `zipFileBlob`. It // is also returned by zipWriter.close() for more convenience. const zipFileBlob = await zipFileWriter.getData(); // ---- // Read the zip file // ---- // Creates a BlobReader object used to read `zipFileBlob`. const zipFileReader = new BlobReader(zipFileBlob); // Creates a TextWriter object where the content of the first entry in the zip // will be written. const helloWorldWriter = new TextWriter(); // Creates a ZipReader object reading the zip content via `zipFileReader`, // retrieves metadata (name, dates, etc.) of the first entry, retrieves its // content via `helloWorldWriter`, and closes the reader. const zipReader = new ZipReader(zipFileReader); const firstEntry = (await zipReader.getEntries()).shift(); const helloWorldText = await firstEntry.getData(helloWorldWriter); await zipReader.close(); // Displays "Hello world!". console.log(helloWorldText); ``` -------------------------------- ### ZipReader Class Overview Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/ZipReader.md Provides an overview of the ZipReader class, its purpose, and an example of how to use it to read the content of a zip file. ```APIDOC ## Class: ZipReader Defined in: [index.d.ts:738](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L738) Represents an instance used to read a zip file. ### Example Here is an example showing how to read the text data of the first entry from a zip file: ```javascript // create a BlobReader to read with a ZipReader the zip from a Blob object const reader = new zip.ZipReader(new zip.BlobReader(blob)); // get all entries from the zip const entries = await reader.getEntries(); if (entries.length) { // get first entry content as text by using a TextWriter const text = await entries[0].getData( // writer new zip.TextWriter(), // options { onprogress: (index, max) => { // onprogress callback } } ); // text contains the entry data as a String console.log(text); } // close the ZipReader await reader.close(); ``` ### Type Parameters #### Type `Type` ### Constructors #### Constructor > **new ZipReader**<`Type` > (`reader`, `options?`): `ZipReader` <`Type` Defined in: [index.d.ts:745](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L745) Creates the instance ##### Parameters ###### reader `ReadableStream` <`any` > | [`ReadableReader`](../interfaces/ReadableReader.md) > | [`Reader`](Reader.md) > <`unknown` > >[] | [`ReadableReader`](../interfaces/ReadableReader.md)[] | `ReadableStream` <`any` > >[] | [`Reader`](Reader.md) > <`Type` > > The [Reader](Reader.md) instance used to read data. ##### options? [`ZipReaderConstructorOptions`](../interfaces/ZipReaderConstructorOptions.md) The options. #### Returns `ZipReader` <`Type` > ### Properties #### appendedData? > `optional` **appendedData?**: `Uint8Array` <`ArrayBufferLike` Defined in: [index.d.ts:766](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L766) The data appended after the zip file. *** #### comment > **comment**: `Uint8Array` Defined in: [index.d.ts:758](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L758) The global comment of the zip file. *** #### prependedData? > `optional` **prependedData?**: `Uint8Array` <`ArrayBufferLike` Defined in: [index.d.ts:762](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L762) The data prepended before the zip file. ### Methods #### close() > **close**(): `Promise` <`void` > Defined in: [index.d.ts:786](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L786) Closes the zip file #### Returns `Promise` <`void` > *** #### getEntries() > **getEntries**(`options?`): `Promise` <[`Entry`](../type-aliases/Entry.md)[] > Defined in: [index.d.ts:773](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L773) Returns all the entries in the zip file ##### Parameters ###### options? [`ZipReaderGetEntriesOptions`](../interfaces/ZipReaderGetEntriesOptions.md) The options. #### Returns `Promise` <[`Entry`](../type-aliases/Entry.md)[] > A promise resolving to an `array` of [Entry](../type-aliases/Entry.md) instances. *** #### getEntriesGenerator() > **getEntriesGenerator**(`options?`): `AsyncGenerator` <[`Entry`](../type-aliases/Entry.md), `boolean` > Defined in: [index.d.ts:780](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L780) Returns a generator used to iterate on all the entries in the zip file ##### Parameters ###### options? [`ZipReaderGetEntriesOptions`](../interfaces/ZipReaderGetEntriesOptions.md) The options. #### Returns `AsyncGenerator` <[`Entry`](../type-aliases/Entry.md), `boolean` > An asynchronous generator of [Entry](../type-aliases/Entry.md) instances. ``` -------------------------------- ### Hello World with Streams Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/README.md Demonstrates zip file creation and extraction using TransformStreams for handling data as streams. ```js import { BlobReader, ZipReader, ZipWriter } from "@zip-js/zip-js"; // Prefix "@zip-js/zip-js" with "jsr:" for Deno // ---- // Write the zip file // ---- // Creates a TransformStream object, the zip content will be written in the // `writable` property. const zipFileStream = new TransformStream(); // Creates a Promise object resolved to the zip content returned as a Blob // object retrieved from `zipFileStream.readable`. const zipFileBlobPromise = new Response(zipFileStream.readable).blob(); // Creates a ReadableStream object storing the text of the entry to add in the // zip (i.e. "Hello world!"). const helloWorldReadable = new Blob(["Hello world!"]).stream(); // Creates a ZipWriter object writing data into `zipFileStream.writable`, adds // the entry "hello.txt" containing the text "Hello world!" retrieved from // `helloWorldReadable`, and closes the writer. const zipWriter = new ZipWriter(zipFileStream.writable); await zipWriter.add("hello.txt", helloWorldReadable); await zipWriter.close(); // Retrieves the Blob object containing the zip content into `zipFileBlob`. const zipFileBlob = await zipFileBlobPromise; // ---- // Read the zip file // ---- // Creates a BlobReader object used to read `zipFileBlob`. const zipFileReader = new BlobReader(zipFileBlob); // Creates a TransformStream object, the content of the first entry in the zip // will be written in the `writable` property. const helloWorldStream = new TransformStream(); // Creates a Promise object resolved to the content of the first entry returned // as text from `helloWorldStream.readable`. const helloWorldTextPromise = new Response(helloWorldStream.readable).text(); // Creates a ZipReader object reading the zip content via `zipFileReader`, // retrieves metadata (name, dates, etc.) of the first entry, retrieves its // content into `helloWorldStream.writable`, and closes the reader. const zipReader = new ZipReader(zipFileReader); const firstEntry = (await zipReader.getEntries()).shift(); await firstEntry.getData(helloWorldStream.writable); await zipReader.close(); // Displays "Hello world!". const helloWorldText = await helloWorldTextPromise; console.log(helloWorldText); ``` -------------------------------- ### EntryDataOnprogressOptions Interface Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/EntryDataOnprogressOptions.md The EntryDataOnprogressOptions interface defines the structure for progress callback options used in various data operations within the Zip.js library, such as getting entry data, adding files to a zip archive, and exporting directory entries. ```APIDOC ## Interface: EntryDataOnprogressOptions ### Description Represents options passed to `FileEntry#getData`, `ZipWriter.add`, and `ZipDirectory.export*`. ### Methods #### `onstart()` - **Description**: The function called when starting compression/decompression. - **Parameters**: - `total` (number) - The total number of bytes. - **Returns**: `void` | `Promise` - An empty promise or `undefined`. #### `onprogress()` - **Description**: The function called during compression/decompression. - **Parameters**: - `progress` (number) - The current progress in bytes. - `total` (number) - The total number of bytes. - **Returns**: `void` | `Promise` - An empty promise or `undefined`. #### `onend()` - **Description**: The function called when ending compression/decompression. - **Parameters**: - `computedSize` (number) - The total number of bytes (computed). - **Returns**: `void` | `Promise` - An empty promise or `undefined`. ### Extended By - `EntryGetDataOptions` - `ZipWriterAddDataOptions` - `ZipDirectoryEntryExportOptions` ``` -------------------------------- ### new FS() Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/FS.md Constructor to initialize a new Filesystem instance. ```APIDOC ## Constructor new FS() ### Description Creates a new instance of the FS class to manage zip archive contents. ### Returns - **FS** - A new filesystem instance. ``` -------------------------------- ### configure() Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/functions/configure.md Configures the zip.js library settings. ```APIDOC ## configure() ### Description Configures the zip.js library by applying the provided configuration object. ### Parameters #### Request Body - **configuration** (Configuration) - Required - The configuration object containing library settings. ``` -------------------------------- ### Track Compression/Decompression Progress with Callbacks Source: https://context7.com/gildas-lormeau/zip.js/llms.txt Use onstart, onprogress, and onend callbacks to monitor individual entry compression and overall archive writing. This is useful for providing user feedback during long operations. ```javascript import { ZipReader, ZipWriter, BlobReader, BlobWriter, TextReader, TextWriter } from "@zip.js/zip.js"; // Track progress when adding entries const zipWriter = new ZipWriter(new BlobWriter(), { level: 9 }); // Progress callback for individual entry compression await zipWriter.add("large-file.txt", new TextReader("A".repeat(1000000))), { onstart: (total) => { console.log(`Starting compression, total size: ${total} bytes`); }, onprogress: (progress, total) => { const percent = Math.round((progress / total) * 100); console.log(`Compressing: ${percent}%`); }, onend: (computedSize) => { console.log(`Compression complete, output size: ${computedSize} bytes`); } }); // Progress callback when closing (writing directory) await zipWriter.close(undefined, { onprogress: (index, total, entry) => { console.log(`Writing entry ${index + 1}/${total}: ${entry.filename}`); } }); // Track progress when reading entries const zipReader = new ZipReader(new BlobReader(zipBlob)); // Progress when getting entries const entries = await zipReader.getEntries({ onprogress: (index, total, entry) => { console.log(`Reading entry ${index + 1}/${total}: ${entry.filename}`); } }); // Progress when extracting entry data for (const entry of entries) { if (!entry.directory) { await entry.getData(new TextWriter(), { onstart: (total) => console.log(`Extracting ${entry.filename}...`), onprogress: (progress, total) => { console.log(`${entry.filename}: ${Math.round((progress / total) * 100)}%`); }, onend: () => console.log(`${entry.filename} complete`) }); } } await zipReader.close(); ``` -------------------------------- ### Initializable.init() Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/Initializable.md The init method is an optional asynchronous function used to initialize instances that read or write data. ```APIDOC ## init() ### Description Initializes the instance asynchronously. This method is part of the Initializable interface used by Reader and Writer classes. ### Returns - **Promise** - A promise that resolves when the initialization is complete. ``` -------------------------------- ### Configure global settings Source: https://context7.com/gildas-lormeau/zip.js/llms.txt Sets global options for worker management, compression streams, and URI locations. ```javascript import { configure, terminateWorkers } from "@zip.js/zip.js"; // Basic configuration configure({ maxWorkers: 4, // Number of web workers (default: navigator.hardwareConcurrency) terminateWorkerTimeout: 5000, // Idle worker termination delay in ms chunkSize: 65536, // Chunk size for compression (default: 64KB) useWebWorkers: true, // Enable web workers useCompressionStream: true // Use native CompressionStream API }); // Configure worker URI for CSP compliance import workerURI from "@zip.js/zip.js/dist/zip-web-worker.js?url"; configure({ workerURI: workerURI }); // Configure WASM module location import wasmURI from "@zip.js/zip.js/dist/zip-module.wasm?url"; configure({ wasmURI: wasmURI }); // Disable web workers for debugging configure({ useWebWorkers: false, useCompressionStream: true }); // Terminate idle workers manually await terminateWorkers(); // Custom compression/decompression streams configure({ CompressionStream: CustomCompressionStream, DecompressionStream: CustomDecompressionStream }); ``` -------------------------------- ### ZipWriterConstructorOptions - sticky? Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipDirectoryEntryExportOptions.md Sets the sticky bit when writing the Unix mode. ```APIDOC ## ZipWriterConstructorOptions - sticky? ### Description `true` to set the sticky bit when writing the Unix mode. ### Method Not applicable (Option) ### Endpoint Not applicable (Option) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **sticky?** (boolean) - Optional - `true` to set the sticky bit when writing the Unix mode. ### Request Example None ### Response None ``` -------------------------------- ### Writer Constructor Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/Writer.md Initializes a new instance of the Writer class. ```APIDOC ## Constructor: new Writer() ### Description Initializes a new instance of the Writer class. ### Returns `Writer` - A new instance of the Writer class. ``` -------------------------------- ### addFileSystemHandle() Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/FS.md Adds an entry with content provided via a FileSystemHandle instance. ```APIDOC ## addFileSystemHandle() ### Description Adds an entry with content provided via a FileSystemHandle instance. ### Parameters #### Path Parameters - **fileSystemHandle** (FileSystemHandleLike) - Required - The fileSystemHandle instance. - **options** (ZipWriterAddDataOptions) - Optional - The options. ### Response - **Returns** (Promise) - A promise resolving to an array of ZipFileEntry or ZipDirectoryEntry instances. ``` -------------------------------- ### Constructor: new Data64URIWriter Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/Data64URIWriter.md Creates a new instance of Data64URIWriter to handle data output as a Base64 Data URI. ```APIDOC ## Constructor new Data64URIWriter ### Description Creates the Data64URIWriter instance. ### Parameters #### Path Parameters - **mimeString** (string) - Optional - The MIME type of the content. ### Response - **Data64URIWriter** (object) - The initialized writer instance. ``` -------------------------------- ### ZipWriterStream Constructor Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/ZipWriterStream.md Initializes a new instance of the ZipWriterStream class. ```APIDOC ## new ZipWriterStream(options?) ### Description Creates a new stream instance used to create a zipped stream. ### Parameters #### Path Parameters - **options** (ZipWriterConstructorOptions) - Optional - The configuration options for the ZipWriter. ``` -------------------------------- ### Configuration Options Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipDirectoryEntryImportHttpOptions.md Configuration properties for controlling HTTP behavior and background processing in zip.js. ```APIDOC ### Configuration Options #### useRangeHeader (boolean) - Optional - Default: false - Description: Set to true to use Range headers when fetching data from servers that support Accept-Ranges. #### useWebWorkers (boolean) - Optional - Default: true - Description: Set to true to use web workers for non-blocking compression/decompression. #### useXHR (boolean) - Optional - Default: false - Description: Set to true to use XMLHttpRequest instead of fetch for data retrieval. ``` -------------------------------- ### Compress data with ZipWriterStream Source: https://context7.com/gildas-lormeau/zip.js/llms.txt Demonstrates single-file compression using pipeThrough and multi-file compression using pipeTo with ZipWriterStream. ```javascript import { ZipWriterStream } from "@zip.js/zip.js"; // Simple single-file compression with pipeThrough const readable = new ReadableStream({ start(controller) { for (let i = 0; i < 1000; i++) { controller.enqueue(new TextEncoder().encode(`Line ${i}\n`)); } controller.close(); } }); const zipStream = new ZipWriterStream(); const zipBlob = await new Response( readable.pipeThrough(zipStream.transform("numbers.txt")) ).blob(); // Multiple files with pipeTo const zipperStream = new ZipWriterStream({ level: 9 }); // Collect output const outputPromise = new Response(zipperStream.readable).blob(); // Add multiple files concurrently const file1Stream = new ReadableStream({ start(controller) { controller.enqueue(new TextEncoder().encode("Content of file 1")); controller.close(); } }); const file2Stream = new ReadableStream({ start(controller) { controller.enqueue(new TextEncoder().encode("Content of file 2")); controller.close(); } }); await Promise.all([ file1Stream.pipeTo(zipperStream.writable("documents/file1.txt")), file2Stream.pipeTo(zipperStream.writable("documents/file2.txt")) ]); await zipperStream.close(); const archiveBlob = await outputPromise; ``` -------------------------------- ### ZipReaderConstructorOptions Interface Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipReaderConstructorOptions.md Configuration options for the ZipReader constructor. ```APIDOC ## ZipReaderConstructorOptions ### Description Represents the options passed to the constructor of ZipReader and related import methods. ### Properties - **checkOverlappingEntry** (boolean) - Optional - If true, throws an ERR_OVERLAPPING_ENTRY error if the entry overlaps with another entry already processed. Default: false. - **checkOverlappingEntryOnly** (boolean) - Optional - If true, throws an ERR_OVERLAPPING_ENTRY error without attempting to read the content. Default: false. - **checkPasswordOnly** (boolean) - Optional - If true, checks only if the password is valid. Default: false. - **checkSignature** (boolean) - Optional - If true, checks the signature of the entry. Default: false. - **commentEncoding** (string) - Optional - The encoding of the entry comment. - **extractAppendedData** (boolean) - Optional - If true, extracts appended data into ZipReader#appendedData. Default: false. - **extractPrependedData** (boolean) - Optional - If true, extracts prepended data into ZipReader#prependedData. Default: false. - **filenameEncoding** (string) - Optional - The encoding of the entry filename. - **passThrough** (boolean) - Optional - If true, reads data as-is without decompression or decryption. ``` -------------------------------- ### Constructor: new HttpReader Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/HttpReader.md Initializes a new instance of the HttpReader to fetch data from a specified URL. ```APIDOC ## Constructor: new HttpReader ### Description Creates a new HttpReader instance to read data from a URL. ### Parameters - **url** (string | URL) - Required - The URL of the data. - **options** (HttpOptions) - Optional - Configuration options for the HTTP request. ### Request Example const reader = new HttpReader("https://example.com/file.zip"); ``` -------------------------------- ### configure() - wasmURI Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/Configuration.md Sets the URI for the WebAssembly module used for compression and decompression. ```APIDOC ## configure() - wasmURI ### Description The URI of the WebAssembly module used by default implementations to compress/decompress data. It is ignored if `useCompressionStream` is set to `true` and `CompressionStream`/`DecompressionStream` are supported by the environment. ### Parameters #### Request Body - **wasmURI** (string) - Optional - The URI of the WebAssembly module. ### Request Example ```javascript import wasmURI from "@zip.js/zip.js/dist/zip-module.wasm?url"; configure({ wasmURI }); ``` ### Default Value "./core/streams/zlib-wasm/zlib-streams.wasm" ``` -------------------------------- ### Read zip file content with ZipReader Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/ZipReader.md Demonstrates initializing a ZipReader with a BlobReader, retrieving entries, and extracting the first entry as text. ```javascript // create a BlobReader to read with a ZipReader the zip from a Blob object const reader = new zip.ZipReader(new zip.BlobReader(blob)); // get all entries from the zip const entries = await reader.getEntries(); if (entries.length) { // get first entry content as text by using a TextWriter const text = await entries[0].getData( // writer new zip.TextWriter(), // options { onprogress: (index, max) => { // onprogress callback } } ); // text contains the entry data as a String console.log(text); } // close the ZipReader await reader.close(); ``` -------------------------------- ### Decompressing a zip file with ZipReaderStream Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/ZipReaderStream.md Demonstrates how to fetch a zip file, decompress it using ZipReaderStream, and save the contents to the local file system in a Deno environment. ```typescript import {resolve} from "https://deno.land/std/path/mod.ts"; import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts"; for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) { const fullPath = resolve(destination, entry.filename); if (entry.directory) { await ensureDir(fullPath); continue; } await ensureFile(fullPath); await entry.readable?.pipeTo((await Deno.create(fullPath)).writable); } ``` -------------------------------- ### ZipWriterConstructorOptions - usdz? Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipDirectoryEntryExportOptions.md Enables USDZ specification compatibility for zip files. ```APIDOC ## ZipWriterConstructorOptions - usdz? ### Description `true` to produce zip files compatible with the USDZ specification. ### Method Not applicable (Option) ### Endpoint Not applicable (Option) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **usdz?** (boolean) - Optional - `true` to produce zip files compatible with the USDZ specification. Defaults to `false`. ### Request Example None ### Response None ``` -------------------------------- ### GetEntriesOptions Interface Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/GetEntriesOptions.md Details the properties and methods available for configuring entry retrieval options in Zip.js. ```APIDOC ## Interface: GetEntriesOptions Defined in: [index.d.ts:820](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L820) Represents options passed to the constructor of [ZipReader](../classes/ZipReader.md), [ZipReader#getEntries](../classes/ZipReader.md#getentries) and [ZipReader#getEntriesGenerator](../classes/ZipReader.md#getentriesgenerator). ### Properties #### commentEncoding? - **commentEncoding** (string) - Optional - The encoding of the comment of the entry. #### filenameEncoding? - **filenameEncoding** (string) - Optional - The encoding of the filename of the entry. ### Methods #### decodeText() - **decodeText**(`value`: Uint8Array, `encoding`: string): `string` | `undefined` - Optional - The function called for decoding the filename and the comment of the entry. ##### Parameters - **value** (Uint8Array) - The raw text value. - **encoding** (string) - The encoding of the text. ##### Returns - `string` | `undefined` - The decoded text value or `undefined` if the raw text value should be decoded by zip.js. ``` -------------------------------- ### ZipReaderOptions Interface Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipReaderOptions.md Options passed to the constructor of ZipReader and FileEntry#getData. ```APIDOC ## Interface: ZipReaderOptions ### Description Represents options passed to the constructor of [ZipReader](../classes/ZipReader.md) and [FileEntry#getData](FileEntry.md#getdata). ### Properties #### checkOverlappingEntry? (boolean) Optional. `true` to throw an [ERR_OVERLAPPING_ENTRY](../variables/ERR_OVERLAPPING_ENTRY.md) error when calling [FileEntry#getData](FileEntry.md#getdata) if the entry overlaps with another entry on which [FileEntry#getData](FileEntry.md#getdata) has already been called (with the option `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`). Default Value: `false` #### checkOverlappingEntryOnly? (boolean) Optional. `true` to throw an [ERR_OVERLAPPING_ENTRY](../variables/ERR_OVERLAPPING_ENTRY.md) error when calling [FileEntry#getData](FileEntry.md#getdata) if the entry overlaps with another entry on which [FileEntry#getData](FileEntry.md#getdata) has already been called (with the option `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`) without trying to read the content of the entry. Default Value: `false` #### checkPasswordOnly? (boolean) Optional. `true` to check only if the password is valid. Default Value: `false` #### checkSignature? (boolean) Optional. `true` to check the signature of the entry. Default Value: `false` #### passThrough? (boolean) Optional. `true` to read the data as-is without decompressing it and without decrypting it. #### password? (string) Optional. The password used to decrypt the content of the entry. #### preventClose? (boolean) Optional. `true` to prevent closing of [Writer#writable](../classes/Writer.md#writable) when calling [FileEntry#getData](FileEntry.md#getdata). Default Value: `false` #### rawPassword? (Uint8Array) Optional. The password used to encrypt the content of the entry (raw). #### signal? (AbortSignal) Optional. The `AbortSignal` instance used to cancel the decompression. ``` -------------------------------- ### Filesystem API (fs) Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/variables/fs.md The 'fs' variable provides access to the Filesystem API. It exposes constructors for managing filesystem entries within zip archives. ```APIDOC ## Variable: fs > `const` **fs**: `object` Defined in: [index.d.ts:2222](https://github.com/gildas-lormeau/zip.js/blob/5484569bd1fe28423166efd99cd7ee7147ada8d8/index.d.ts#L2222) The Filesystem API. ### Type Declaration #### FS > **FS**: *typeof* [`FS`](../classes/FS.md) The Filesystem constructor. ##### Default Value [FS](../classes/FS.md) #### ZipDirectoryEntry > **ZipDirectoryEntry**: *typeof* [`ZipDirectoryEntry`](../classes/ZipDirectoryEntry.md) The [ZipDirectoryEntry](../classes/ZipDirectoryEntry.md) constructor. ##### Default Value [ZipDirectoryEntry](../classes/ZipDirectoryEntry.md) #### ZipFileEntry > **ZipFileEntry**: *typeof* [`ZipFileEntry`](../classes/ZipFileEntry.md) The [ZipFileEntry](../classes/ZipFileEntry.md) constructor. ##### Default Value [ZipFileEntry](../classes/ZipFileEntry.md) ``` -------------------------------- ### Constructor new TextWriter Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/TextWriter.md Creates a new instance of TextWriter with an optional encoding parameter. ```APIDOC ## Constructor new TextWriter ### Description Creates the TextWriter instance to handle text data writing. ### Parameters #### Parameters - **encoding** (string) - Optional - The encoding of the text. ### Request Example const writer = new TextWriter("utf-8"); ``` -------------------------------- ### ZipWriterConstructorOptions - useCompressionStream? Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipDirectoryEntryExportOptions.md Utilizes native CompressionStream/DecompressionStream API. ```APIDOC ## ZipWriterConstructorOptions - useCompressionStream? ### Description `true` to use the native API `CompressionStream`/`DecompressionStream` to compress/decompress data. ### Method Not applicable (Option) ### Endpoint Not applicable (Option) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **useCompressionStream?** (boolean) - Optional - `true` to use the native API `CompressionStream`/`DecompressionStream` to compress/decompress data. Defaults to `true`. ### Request Example None ### Response None ``` -------------------------------- ### addFileSystemEntry() Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/FS.md Adds an entry with content provided via a FileSystemEntry instance. ```APIDOC ## addFileSystemEntry() ### Description Adds an entry with content provided via a FileSystemEntry instance. ### Parameters #### Path Parameters - **fileSystemEntry** (FileSystemEntryLike) - Required - The FileSystemEntry instance. - **options** (ZipWriterAddDataOptions) - Optional - The options. ### Response - **Returns** (Promise) - A promise resolving to an array of ZipFileEntry or ZipDirectoryEntry instances. ``` -------------------------------- ### ZipWriterConstructorOptions - useUnicodeFileNames? Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/ZipDirectoryEntryExportOptions.md Controls UTF-8 encoding for file names. ```APIDOC ## ZipWriterConstructorOptions - useUnicodeFileNames? ### Description `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D - Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437. Note that this does not ensure that the file names are in the correct encoding. ### Method Not applicable (Option) ### Endpoint Not applicable (Option) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **useUnicodeFileNames?** (boolean) - Optional - `true` to mark the file names as UTF-8, `false` for IBM Code Page 437. Defaults to `true`. ### Request Example None ### Response None ``` -------------------------------- ### Constructor: new SplitDataReader Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/SplitDataReader.md Initializes a new instance of SplitDataReader to handle split data sources. ```APIDOC ## Constructor: new SplitDataReader ### Description Creates a new SplitDataReader instance to read data provided as an array of readers or streams. ### Parameters #### Request Body - **value** (Reader[] | ReadableReader[] | ReadableStream[]) - Required - The data sources to read from. ``` -------------------------------- ### Constructor: new Data64URIReader Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/Data64URIReader.md Creates a new instance of Data64URIReader to process a Base64 encoded Data URI string. ```APIDOC ## Constructor: new Data64URIReader ### Description Creates a new Data64URIReader instance to read data provided as a Base64 encoded Data URI string. ### Parameters - **value** (string) - Required - The Base64 encoded data string to read. ### Request Example const reader = new Data64URIReader("data:text/plain;base64,SGVsbG8gV29ybGQ="); ``` -------------------------------- ### ZipReader Import Method Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/FS.md Method for importing zip files from a Blob. ```APIDOC ## POST /zip/importBlob ### Description Extracts a zip file provided as a `Blob` instance into the entry. ### Method POST ### Endpoint /zip/importBlob ### Parameters #### Query Parameters - **blob** (Blob) - Required - The `Blob` instance. - **options** (ZipReaderConstructorOptions) - Optional - The options. ### Response #### Success Response (200) - **Array** (Array) - An array of `ZipEntry` instances. ### Request Example ```json { "blob": "", "options": { "password": "secret" } } ``` ### Response Example ```json { "zipEntries": [ { "id": 1, "name": "file1.txt", "directory": false } ] } ``` ``` -------------------------------- ### Implement a custom Writer class Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/Writer.md Extend the base Writer class to create custom data output formats, such as binary strings. Ensure the constructor calls super() and the class implements the necessary data handling methods. ```javascript class BinaryStringWriter extends Writer { constructor() { super(); this.binaryString = ""; } writeUint8Array(array) { for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) { this.binaryString += String.fromCharCode(array[indexCharacter]); } } getData() { return this.binaryString; } } ``` -------------------------------- ### addText() Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/classes/FS.md Adds an entry to the zip directory with content provided as a string. ```APIDOC ## addText() ### Description Adds an entry with content provided as text. ### Parameters #### Path Parameters - **name** (string) - Required - The relative filename of the entry. - **text** (string) - Required - The text content. - **options** (ZipWriterAddDataOptions) - Optional - The options. ### Response - **ZipFileEntry** - A ZipFileEntry instance. ``` -------------------------------- ### EntryGetDataOptions Interface Source: https://github.com/gildas-lormeau/zip.js/blob/master/docs/interfaces/EntryGetDataOptions.md The EntryGetDataOptions interface defines the configuration options for retrieving data from a zip entry. It extends several other interfaces, inheriting their properties. ```APIDOC ## Interface: EntryGetDataOptions ### Description Represents the options passed to `FileEntry#getData` and `ZipFileEntry.get*` methods. ### Extends - `EntryDataOnprogressOptions` - `ZipReaderOptions` - `WorkerConfiguration` ### Extended by - `EntryGetDataCheckPasswordOptions` ### Properties #### checkOverlappingEntry? (boolean) Optional. If `true`, throws an `ERR_OVERLAPPING_ENTRY` error when calling `FileEntry#getData` if the entry overlaps with another entry on which `FileEntry#getData` has already been called with `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`. **Default Value**: `false` **Inherited from**: `ZipReaderOptions` #### checkOverlappingEntryOnly? (boolean) Optional. If `true`, throws an `ERR_OVERLAPPING_ENTRY` error when calling `FileEntry#getData` if the entry overlaps with another entry on which `FileEntry#getData` has already been called (with `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`) without trying to read the content of the entry. **Default Value**: `false` **Inherited from**: `ZipReaderOptions` #### checkPasswordOnly? (boolean) Optional. If `true`, checks only if the password is valid. **Default Value**: `false` **Inherited from**: `ZipReaderOptions` #### checkSignature? (boolean) Optional. If `true`, checks the signature of the entry. **Default Value**: `false` **Inherited from**: `ZipReaderOptions` #### passThrough? (boolean) Optional. If `true`, reads the data as-is without decompressing it and without decrypting it. **Inherited from**: `ZipReaderOptions` #### password? (string) Optional. The password used to decrypt the content of the entry. **Inherited from**: `ZipReaderOptions` #### preventClose? (boolean) Optional. If `true`, prevents closing of `Writer#writable` when calling `FileEntry#getData`. **Default Value**: `false` **Inherited from**: `ZipReaderOptions` #### rawPassword? (Uint8Array) Optional. The password used to encrypt the content of the entry (raw). **Inherited from**: `ZipReaderOptions` #### signal? (AbortSignal) Optional. The `AbortSignal` instance used to cancel the decompression. ```