@cj-tech-master/excelts 6.0.0-beta.4 → 6.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/modules/archive/create-archive.d.ts +23 -0
- package/dist/browser/modules/archive/create-archive.js +13 -0
- package/dist/browser/modules/archive/fs/archive-file.d.ts +1 -1
- package/dist/browser/modules/archive/fs/types.d.ts +1 -1
- package/dist/browser/modules/archive/index.base.d.ts +6 -4
- package/dist/browser/modules/archive/index.base.js +5 -5
- package/dist/browser/modules/archive/read-archive.d.ts +27 -0
- package/dist/browser/modules/archive/read-archive.js +12 -0
- package/dist/browser/modules/archive/unzip/index.d.ts +0 -27
- package/dist/browser/modules/archive/unzip/index.js +0 -4
- package/dist/browser/modules/archive/{io → unzip}/remote-zip-reader.d.ts +1 -1
- package/dist/browser/modules/archive/{io → unzip}/remote-zip-reader.js +3 -3
- package/dist/browser/modules/archive/unzip/zip-reader.d.ts +1 -2
- package/dist/browser/modules/archive/unzip/zip-reader.js +0 -3
- package/dist/browser/modules/archive/zip/index.d.ts +0 -24
- package/dist/browser/modules/archive/zip/index.js +0 -4
- package/dist/browser/modules/archive/zip/zip-archive.d.ts +1 -2
- package/dist/browser/modules/archive/zip/zip-archive.js +42 -140
- package/dist/browser/modules/archive/zip/zip-editor.js +117 -207
- package/dist/browser/modules/archive/zip/zip-output-pipeline.d.ts +55 -0
- package/dist/browser/modules/archive/zip/zip-output-pipeline.js +127 -0
- package/dist/cjs/modules/archive/create-archive.js +16 -0
- package/dist/cjs/modules/archive/index.base.js +7 -9
- package/dist/cjs/modules/archive/read-archive.js +15 -0
- package/dist/cjs/modules/archive/unzip/index.js +0 -5
- package/dist/cjs/modules/archive/{io → unzip}/remote-zip-reader.js +3 -3
- package/dist/cjs/modules/archive/unzip/zip-reader.js +0 -4
- package/dist/cjs/modules/archive/zip/index.js +0 -5
- package/dist/cjs/modules/archive/zip/zip-archive.js +40 -139
- package/dist/cjs/modules/archive/zip/zip-editor.js +115 -205
- package/dist/cjs/modules/archive/zip/zip-output-pipeline.js +130 -0
- package/dist/esm/modules/archive/create-archive.js +13 -0
- package/dist/esm/modules/archive/index.base.js +5 -5
- package/dist/esm/modules/archive/read-archive.js +12 -0
- package/dist/esm/modules/archive/unzip/index.js +0 -4
- package/dist/esm/modules/archive/{io → unzip}/remote-zip-reader.js +3 -3
- package/dist/esm/modules/archive/unzip/zip-reader.js +0 -3
- package/dist/esm/modules/archive/zip/index.js +0 -4
- package/dist/esm/modules/archive/zip/zip-archive.js +42 -140
- package/dist/esm/modules/archive/zip/zip-editor.js +117 -207
- package/dist/esm/modules/archive/zip/zip-output-pipeline.js +127 -0
- package/dist/iife/excelts.iife.js +1 -1
- package/dist/iife/excelts.iife.min.js +1 -1
- package/dist/types/modules/archive/create-archive.d.ts +23 -0
- package/dist/types/modules/archive/fs/archive-file.d.ts +1 -1
- package/dist/types/modules/archive/fs/types.d.ts +1 -1
- package/dist/types/modules/archive/index.base.d.ts +6 -4
- package/dist/types/modules/archive/read-archive.d.ts +27 -0
- package/dist/types/modules/archive/unzip/index.d.ts +0 -27
- package/dist/types/modules/archive/{io → unzip}/remote-zip-reader.d.ts +1 -1
- package/dist/types/modules/archive/unzip/zip-reader.d.ts +1 -2
- package/dist/types/modules/archive/zip/index.d.ts +0 -24
- package/dist/types/modules/archive/zip/zip-archive.d.ts +1 -2
- package/dist/types/modules/archive/zip/zip-output-pipeline.d.ts +55 -0
- package/package.json +1 -1
- package/dist/browser/modules/archive/formats/index.d.ts +0 -9
- package/dist/browser/modules/archive/formats/index.js +0 -28
- package/dist/cjs/modules/archive/formats/index.js +0 -32
- package/dist/esm/modules/archive/formats/index.js +0 -28
- package/dist/types/modules/archive/formats/index.d.ts +0 -9
- /package/dist/browser/modules/archive/{formats → shared}/types.d.ts +0 -0
- /package/dist/browser/modules/archive/{formats → shared}/types.js +0 -0
- /package/dist/cjs/modules/archive/{formats → shared}/types.js +0 -0
- /package/dist/esm/modules/archive/{formats → shared}/types.js +0 -0
- /package/dist/types/modules/archive/{formats → shared}/types.d.ts +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TarArchive } from "./tar/tar-archive.js";
|
|
2
|
+
import { ZipArchive, type ZipOptionsTar, type ZipOptionsZip } from "./zip/zip-archive.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a new archive
|
|
5
|
+
*
|
|
6
|
+
* @param options - Archive options including format
|
|
7
|
+
* @returns ZipArchive or TarArchive depending on format option
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Create ZIP archive (default)
|
|
12
|
+
* const zipArchive = zip();
|
|
13
|
+
* zipArchive.add("file.txt", "content");
|
|
14
|
+
* const zipBytes = await zipArchive.bytes();
|
|
15
|
+
*
|
|
16
|
+
* // Create TAR archive
|
|
17
|
+
* const tarArchive = zip({ format: "tar" });
|
|
18
|
+
* tarArchive.add("file.txt", "content");
|
|
19
|
+
* const tarBytes = await tarArchive.bytes();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function zip(options: ZipOptionsTar): TarArchive;
|
|
23
|
+
export declare function zip(options?: ZipOptionsZip): ZipArchive;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TarArchive } from "./tar/tar-archive.js";
|
|
2
|
+
import { ZipArchive } from "./zip/zip-archive.js";
|
|
3
|
+
export function zip(options = {}) {
|
|
4
|
+
if (options.format === "tar") {
|
|
5
|
+
return new TarArchive({
|
|
6
|
+
modTime: options.modTime,
|
|
7
|
+
signal: options.signal,
|
|
8
|
+
onProgress: options.onProgress,
|
|
9
|
+
progressIntervalMs: options.progressIntervalMs
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return new ZipArchive({ ...options, format: "zip" });
|
|
13
|
+
}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* @module
|
|
31
31
|
*/
|
|
32
32
|
import { type ArchiveSink } from "../io/archive-sink.js";
|
|
33
|
-
import type { ArchiveFormat } from "../
|
|
33
|
+
import type { ArchiveFormat } from "../shared/types.js";
|
|
34
34
|
import type { AddFileOptions, AddDirectoryOptions, AddGlobOptions, AddTarFileOptions, AddTarDirectoryOptions, AddTarGlobOptions, ExtractToOptions, ArchiveFileOptions, ArchiveFileOptionsZip, ArchiveFileOptionsTar, OpenArchiveOptionsZip, OpenArchiveOptionsTar, WriteArchiveOptions, ArchiveEntryInfo, ZipEntryInfo, ArchiveStreamOptions, ArchiveStreamOperation } from "./types.js";
|
|
35
35
|
/**
|
|
36
36
|
* Unified archive file class supporting both ZIP and TAR formats.
|
|
@@ -11,7 +11,7 @@ import type { Zip64Mode } from "../zip-spec/zip-records.js";
|
|
|
11
11
|
import type { ZipEncryptionMethod } from "../crypto/index.js";
|
|
12
12
|
import type { ZipPathOptions } from "../zip-spec/zip-path.js";
|
|
13
13
|
import type { ZipStringEncoding } from "../shared/text.js";
|
|
14
|
-
import type { ArchiveFormat } from "../
|
|
14
|
+
import type { ArchiveFormat } from "../shared/types.js";
|
|
15
15
|
export type { ArchiveFormat };
|
|
16
16
|
/** Entry data passed to transform function */
|
|
17
17
|
export interface TransformEntryData {
|
|
@@ -9,13 +9,15 @@ export type { ArchiveSource } from "./io/archive-source.js";
|
|
|
9
9
|
export type { ArchiveSink } from "./io/archive-sink.js";
|
|
10
10
|
export { toAsyncIterable, toReadableStream } from "./io/archive-source.js";
|
|
11
11
|
export { HttpRangeReader, BufferReader, RangeNotSupportedError, HttpRangeError, type RandomAccessReader, type HttpRangeReaderOptions, type HttpRangeReaderStats } from "./io/random-access.js";
|
|
12
|
-
export { RemoteZipReader, Crc32MismatchError, type RemoteZipReaderOptions, type RemoteZipOpenOptions, type RemoteZipStats, type ExtractOptions } from "./
|
|
12
|
+
export { RemoteZipReader, Crc32MismatchError, type RemoteZipReaderOptions, type RemoteZipOpenOptions, type RemoteZipStats, type ExtractOptions } from "./unzip/remote-zip-reader.js";
|
|
13
13
|
export { AbortError, createAbortError, isAbortError, throwIfAborted, ArchiveError, ZipParseError, InvalidZipSignatureError, EocdNotFoundError, DecryptionError, PasswordRequiredError, FileTooLargeError, UnsupportedCompressionError, EntrySizeMismatchError, type EntrySizeMismatchReason } from "./shared/errors.js";
|
|
14
|
-
export { zip
|
|
15
|
-
export { unzip
|
|
14
|
+
export { zip } from "./create-archive.js";
|
|
15
|
+
export { unzip } from "./read-archive.js";
|
|
16
|
+
export type { ArchiveFormat } from "./shared/types.js";
|
|
17
|
+
export { ZipArchive, ZipEditor, editZip, editZipUrl, ZipEditPlan, type ZipOptions, type ZipEntryOptions, type ZipEditOptions, type ZipEditUrlOptions, type ZipEditWarning, type ZipEditOp } from "./zip/index.js";
|
|
18
|
+
export { ZipReader, UnzipEntry, type UnzipOptions } from "./unzip/index.js";
|
|
16
19
|
export type { ZipOperation, ZipProgress, ZipStreamOptions } from "./zip/index.js";
|
|
17
20
|
export type { UnzipOperation, UnzipProgress, UnzipStreamOptions } from "./unzip/index.js";
|
|
18
|
-
export { createArchive, createReader } from "./formats/index.js";
|
|
19
21
|
export { TAR_BLOCK_SIZE, TAR_TYPE, TarArchive, TarReader, TarReaderEntry, createTarArchive, createTarReader, tar, tarSync, parseTar, parseTarStream, untar, isTarFile, isTarDirectory, isTarSymlink, isTarHardLink, isTarDataEntry, type TarType, type TarEntryInfo, type TarEntry, type TarHeaderOptions, type TarParseOptions, type TarArchiveOptions, type TarArchiveEntryOptions, type TarArchiveProgress, type TarArchiveStreamOptions, type TarArchiveOperation, type TarReaderOptions, type TarReaderProgress, type TarReaderStreamOptions, type TarReaderOperation } from "./tar/index.browser.js";
|
|
20
22
|
export { base64ToUint8Array, uint8ArrayToBase64 } from "../../utils/utils.base.js";
|
|
21
23
|
export { concatUint8Arrays, stringToUint8Array, uint8ArrayToString } from "../../utils/binary.js";
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export { toAsyncIterable, toReadableStream } from "./io/archive-source.js";
|
|
9
9
|
// Random Access / HTTP Range reading
|
|
10
10
|
export { HttpRangeReader, BufferReader, RangeNotSupportedError, HttpRangeError } from "./io/random-access.js";
|
|
11
|
-
export { RemoteZipReader, Crc32MismatchError } from "./
|
|
11
|
+
export { RemoteZipReader, Crc32MismatchError } from "./unzip/remote-zip-reader.js";
|
|
12
12
|
// Abort and Error types - all from centralized errors module
|
|
13
13
|
export {
|
|
14
14
|
// Abort helpers
|
|
@@ -16,10 +16,10 @@ AbortError, createAbortError, isAbortError, throwIfAborted,
|
|
|
16
16
|
// Error classes
|
|
17
17
|
ArchiveError, ZipParseError, InvalidZipSignatureError, EocdNotFoundError, DecryptionError, PasswordRequiredError, FileTooLargeError, UnsupportedCompressionError, EntrySizeMismatchError } from "./shared/errors.js";
|
|
18
18
|
// High-level APIs
|
|
19
|
-
export { zip
|
|
20
|
-
export { unzip
|
|
21
|
-
|
|
22
|
-
export {
|
|
19
|
+
export { zip } from "./create-archive.js";
|
|
20
|
+
export { unzip } from "./read-archive.js";
|
|
21
|
+
export { ZipArchive, ZipEditor, editZip, editZipUrl, ZipEditPlan } from "./zip/index.js";
|
|
22
|
+
export { ZipReader, UnzipEntry } from "./unzip/index.js";
|
|
23
23
|
// TAR archive support (unified API compatible with ZIP)
|
|
24
24
|
// Note: Gzip helpers are exported separately in index.ts / index.browser.ts
|
|
25
25
|
export { TAR_BLOCK_SIZE, TAR_TYPE,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ArchiveSource } from "./io/archive-source.js";
|
|
2
|
+
import { TarReader } from "./tar/tar-archive.js";
|
|
3
|
+
import { ZipReader, type UnzipOptionsTar, type UnzipOptionsZip } from "./unzip/zip-reader.js";
|
|
4
|
+
/**
|
|
5
|
+
* Open an archive for reading
|
|
6
|
+
*
|
|
7
|
+
* @param source - Archive data source
|
|
8
|
+
* @param options - Options including format
|
|
9
|
+
* @returns ZipReader or TarReader depending on format option
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Read ZIP archive (default)
|
|
14
|
+
* const zipReader = unzip(zipBytes);
|
|
15
|
+
* for await (const entry of zipReader.entries()) {
|
|
16
|
+
* console.log(entry.path);
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* // Read TAR archive
|
|
20
|
+
* const tarReader = unzip(tarBytes, { format: "tar" });
|
|
21
|
+
* for await (const entry of tarReader.entries()) {
|
|
22
|
+
* console.log(entry.path);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function unzip(source: ArchiveSource, options: UnzipOptionsTar): TarReader;
|
|
27
|
+
export declare function unzip(source: ArchiveSource, options?: UnzipOptionsZip): ZipReader;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TarReader } from "./tar/tar-archive.js";
|
|
2
|
+
import { ZipReader } from "./unzip/zip-reader.js";
|
|
3
|
+
export function unzip(source, options = {}) {
|
|
4
|
+
if (options.format === "tar") {
|
|
5
|
+
return new TarReader(source, {
|
|
6
|
+
signal: options.signal,
|
|
7
|
+
onProgress: options.onProgress,
|
|
8
|
+
progressIntervalMs: options.progressIntervalMs
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new ZipReader(source, { ...options, format: "zip" });
|
|
12
|
+
}
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
import type { ArchiveSource } from "../io/archive-source.js";
|
|
2
|
-
import type { TarReader } from "../tar/tar-archive.js";
|
|
3
|
-
import type { UnzipOptionsTar, UnzipOptionsZip, ZipReader } from "./zip-reader.js";
|
|
4
1
|
export { UnzipEntry, ZipReader, type UnzipOptions, type UnzipOptionsTar, type UnzipOptionsZip, type UnzipOperation, type UnzipProgress, type UnzipStreamOptions } from "./zip-reader.js";
|
|
5
|
-
/**
|
|
6
|
-
* Open an archive for reading
|
|
7
|
-
*
|
|
8
|
-
* @param source - Archive data source
|
|
9
|
-
* @param options - Options including format
|
|
10
|
-
* @returns ZipReader or TarReader depending on format option
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* // Read ZIP archive (default)
|
|
15
|
-
* const zipReader = unzip(zipBytes);
|
|
16
|
-
* for await (const entry of zipReader.entries()) {
|
|
17
|
-
* console.log(entry.path);
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* // Read TAR archive
|
|
21
|
-
* const tarReader = unzip(tarBytes, { format: "tar" });
|
|
22
|
-
* for await (const entry of tarReader.entries()) {
|
|
23
|
-
* console.log(entry.path);
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare function unzip(source: ArchiveSource, options: UnzipOptionsTar): TarReader;
|
|
28
|
-
export declare function unzip(source: ArchiveSource, options?: UnzipOptionsZip): ZipReader;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { ZipEntryInfo } from "../zip-spec/zip-entry-info.js";
|
|
17
17
|
import { type ZipStringEncoding } from "../shared/text.js";
|
|
18
|
-
import type { RandomAccessReader, HttpRangeReaderOptions } from "
|
|
18
|
+
import type { RandomAccessReader, HttpRangeReaderOptions } from "../io/random-access.js";
|
|
19
19
|
/**
|
|
20
20
|
* Options for RemoteZipReader
|
|
21
21
|
*/
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
import { BinaryReader } from "../zip-spec/binary.js";
|
|
17
17
|
import { crc32 } from "../compression/crc32.browser.js";
|
|
18
18
|
import { zipCryptoVerifyPassword, aesVerifyPassword, AES_PASSWORD_VERIFY_LENGTH, AES_SALT_LENGTH, ZIP_CRYPTO_HEADER_SIZE } from "../crypto/index.js";
|
|
19
|
-
import { processEntryData, processEntryDataStream, LOCAL_HEADER_FIXED_SIZE } from "
|
|
19
|
+
import { processEntryData, processEntryDataStream, LOCAL_HEADER_FIXED_SIZE } from "./zip-extract-core.js";
|
|
20
20
|
import { EMPTY_UINT8ARRAY } from "../shared/bytes.js";
|
|
21
|
-
import { pipeIterableToSink } from "
|
|
21
|
+
import { pipeIterableToSink } from "../io/archive-sink.js";
|
|
22
22
|
import { EOCD_MAX_SEARCH_SIZE, ZIP64_EOCD_LOCATOR_SIZE, findEOCDSignature, parseEOCD, parseZIP64EOCDLocator, parseZIP64EOCD, applyZIP64ToEOCD, parseCentralDirectory } from "../zip-spec/zip-parser-core.js";
|
|
23
23
|
import { resolveZipStringCodec } from "../shared/text.js";
|
|
24
24
|
import { LOCAL_FILE_HEADER_SIG } from "../zip-spec/zip-records.js";
|
|
25
|
-
import { HttpRangeReader } from "
|
|
25
|
+
import { HttpRangeReader } from "../io/random-access.js";
|
|
26
26
|
/**
|
|
27
27
|
* Error thrown when CRC32 validation fails
|
|
28
28
|
*/
|
|
@@ -3,7 +3,7 @@ import { type ParseOptions, type ZipEntry as ParseZipEntry } from "./stream.js";
|
|
|
3
3
|
import { type ArchiveSink } from "../io/archive-sink.js";
|
|
4
4
|
import { type ArchiveSource } from "../io/archive-source.js";
|
|
5
5
|
import type { UnzipOperation, UnzipProgress, UnzipStreamOptions } from "./progress.js";
|
|
6
|
-
import type { ArchiveFormat } from "../
|
|
6
|
+
import type { ArchiveFormat } from "../shared/types.js";
|
|
7
7
|
import type { ZipStringEncoding } from "../shared/text.js";
|
|
8
8
|
import type { ZipEntryType } from "../zip-spec/zip-entry-info.js";
|
|
9
9
|
type PipeToOptions = {
|
|
@@ -101,4 +101,3 @@ export interface UnzipOptionsTar extends UnzipOptions {
|
|
|
101
101
|
export interface UnzipOptionsZip extends UnzipOptions {
|
|
102
102
|
format?: "zip";
|
|
103
103
|
}
|
|
104
|
-
export declare function createZipReader(source: ArchiveSource, options?: UnzipOptionsZip): ZipReader;
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
import type { TarArchive } from "../tar/tar-archive.js";
|
|
2
|
-
import type { ZipArchive, ZipOptionsTar, ZipOptionsZip } from "./zip-archive.js";
|
|
3
1
|
export { ZipEditor, editZip, editZipUrl, type ZipEditOptions, type ZipEditUrlOptions, type ZipEditWarning } from "./zip-editor.js";
|
|
4
2
|
export { ZipEditPlan, type ZipEditOp, type SerializedZipEditOp, type SerializedZipEditPlan } from "./zip-edit-plan.js";
|
|
5
|
-
export type { ArchiveFormat } from "../formats/index.js";
|
|
6
3
|
export { ZipArchive, type ZipOptions, type ZipEntryOptions, type ZipOptionsTar, type ZipOptionsZip, type ZipOperation, type ZipProgress, type ZipStreamOptions } from "./zip-archive.js";
|
|
7
|
-
/**
|
|
8
|
-
* Create a new archive
|
|
9
|
-
*
|
|
10
|
-
* @param options - Archive options including format
|
|
11
|
-
* @returns ZipArchive or TarArchive depending on format option
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Create ZIP archive (default)
|
|
16
|
-
* const zipArchive = zip();
|
|
17
|
-
* zipArchive.add("file.txt", "content");
|
|
18
|
-
* const zipBytes = await zipArchive.bytes();
|
|
19
|
-
*
|
|
20
|
-
* // Create TAR archive
|
|
21
|
-
* const tarArchive = zip({ format: "tar" });
|
|
22
|
-
* tarArchive.add("file.txt", "content");
|
|
23
|
-
* const tarBytes = await tarArchive.bytes();
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function zip(options: ZipOptionsTar): TarArchive;
|
|
27
|
-
export declare function zip(options?: ZipOptionsZip): ZipArchive;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { createArchive } from "../formats/index.js";
|
|
2
1
|
export { ZipEditor, editZip, editZipUrl } from "./zip-editor.js";
|
|
3
2
|
export { ZipEditPlan } from "./zip-edit-plan.js";
|
|
4
3
|
export { ZipArchive } from "./zip-archive.js";
|
|
5
|
-
export function zip(options) {
|
|
6
|
-
return createArchive(options);
|
|
7
|
-
}
|
|
@@ -4,7 +4,7 @@ import { type ArchiveSource } from "../io/archive-source.js";
|
|
|
4
4
|
import { type Zip64Mode } from "../zip-spec/zip-records.js";
|
|
5
5
|
import type { ZipOperation, ZipProgress, ZipStreamOptions } from "./progress.js";
|
|
6
6
|
import type { ZipPathOptions } from "../zip-spec/zip-path.js";
|
|
7
|
-
import type { ArchiveFormat } from "../
|
|
7
|
+
import type { ArchiveFormat } from "../shared/types.js";
|
|
8
8
|
import { type ZipStringEncoding } from "../shared/text.js";
|
|
9
9
|
/** Archive options */
|
|
10
10
|
export interface ZipOptions {
|
|
@@ -118,4 +118,3 @@ export interface ZipOptionsTar extends ZipOptions {
|
|
|
118
118
|
export interface ZipOptionsZip extends ZipOptions {
|
|
119
119
|
format?: "zip";
|
|
120
120
|
}
|
|
121
|
-
export declare function createZipArchive(options?: ZipOptionsZip): ZipArchive;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_ZIP_LEVEL, DEFAULT_ZIP_TIMESTAMPS, REPRODUCIBLE_ZIP_MOD_TIME } from "../shared/defaults.js";
|
|
2
|
-
import { ZipDeflateFile
|
|
2
|
+
import { ZipDeflateFile } from "./stream.js";
|
|
3
3
|
import { createZip, createZipSync } from "./zip-bytes.js";
|
|
4
4
|
import { collect, pipeIterableToSink } from "../io/archive-sink.js";
|
|
5
5
|
import { toAsyncIterable, toUint8Array, toUint8ArraySync, isSyncArchiveSource, isInMemoryArchiveSource } from "../io/archive-source.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ProgressEmitter } from "../shared/progress.js";
|
|
6
|
+
import { throwIfAborted } from "../shared/errors.js";
|
|
7
|
+
import { createZipOperation } from "./zip-output-pipeline.js";
|
|
9
8
|
import { stringToUint8Array as encodeUtf8 } from "../../../utils/binary.js";
|
|
10
9
|
import { buildDataDescriptor, FLAG_DATA_DESCRIPTOR, UINT16_MAX, UINT32_MAX, writeLocalFileHeaderInto } from "../zip-spec/zip-records.js";
|
|
11
10
|
import { isNode } from "../../../utils/env.js";
|
|
@@ -88,147 +87,53 @@ export class ZipArchive {
|
|
|
88
87
|
const signalOpt = options.signal ?? this._streamDefaults.signal;
|
|
89
88
|
const onProgress = options.onProgress ?? this._streamDefaults.onProgress;
|
|
90
89
|
const progressIntervalMs = options.progressIntervalMs ?? this._streamDefaults.progressIntervalMs;
|
|
91
|
-
|
|
92
|
-
const signal = controller.signal;
|
|
93
|
-
const progress = new ProgressEmitter({
|
|
94
|
-
type: "zip",
|
|
95
|
-
phase: "running",
|
|
96
|
-
entriesTotal: this._entries.length,
|
|
97
|
-
entriesDone: 0,
|
|
98
|
-
bytesIn: 0,
|
|
99
|
-
bytesOut: 0,
|
|
100
|
-
zip64: this._options.zip64
|
|
101
|
-
}, onProgress, { intervalMs: progressIntervalMs });
|
|
102
|
-
const queue = createAsyncQueue({
|
|
103
|
-
onCancel: () => {
|
|
104
|
-
// Consumer stopped reading; abort upstream work to avoid buffering.
|
|
105
|
-
try {
|
|
106
|
-
controller.abort("cancelled");
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
// ignore
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
const zip = new StreamingZip((err, data, final) => {
|
|
114
|
-
if (err) {
|
|
115
|
-
progress.update({ phase: progress.snapshot.phase === "aborted" ? "aborted" : "error" });
|
|
116
|
-
queue.fail(err);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (data.length) {
|
|
120
|
-
progress.mutate(s => {
|
|
121
|
-
s.bytesOut += data.length;
|
|
122
|
-
});
|
|
123
|
-
queue.push(data);
|
|
124
|
-
}
|
|
125
|
-
if (final) {
|
|
126
|
-
if (progress.snapshot.phase === "running") {
|
|
127
|
-
progress.update({ phase: "done" });
|
|
128
|
-
}
|
|
129
|
-
queue.close();
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
90
|
+
return createZipOperation(this._entries.length, {
|
|
132
91
|
comment: this._options.comment,
|
|
133
92
|
zip64: this._options.zip64,
|
|
134
93
|
encoding: this._options.encoding
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
const err = createAbortError(signal.reason);
|
|
138
|
-
progress.update({ phase: "aborted" });
|
|
139
|
-
try {
|
|
140
|
-
zip.abort(err);
|
|
141
|
-
}
|
|
142
|
-
catch {
|
|
143
|
-
// ignore
|
|
144
|
-
}
|
|
145
|
-
queue.fail(err);
|
|
146
|
-
};
|
|
147
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
148
|
-
(async () => {
|
|
149
|
-
try {
|
|
150
|
-
for (let i = 0; i < this._entries.length; i++) {
|
|
151
|
-
throwIfAborted(signal);
|
|
152
|
-
const entry = this._entries[i];
|
|
153
|
-
let entryBytesIn = 0;
|
|
154
|
-
progress.update({ currentEntry: { name: entry.name, index: i, bytesIn: 0 } });
|
|
155
|
-
const file = new ZipDeflateFile(entry.name, buildZipDeflateFileOptions(entry.options, {
|
|
156
|
-
level: this._options.level,
|
|
157
|
-
modTime: this._options.modTime,
|
|
158
|
-
timestamps: this._options.timestamps,
|
|
159
|
-
smartStore: this._options.smartStore,
|
|
160
|
-
zip64: this._options.zip64,
|
|
161
|
-
path: this._options.path,
|
|
162
|
-
encoding: this._options.encoding
|
|
163
|
-
}));
|
|
164
|
-
zip.add(file);
|
|
165
|
-
const onChunk = (chunk) => {
|
|
166
|
-
entryBytesIn += chunk.length;
|
|
167
|
-
progress.mutate(s => {
|
|
168
|
-
s.bytesIn += chunk.length;
|
|
169
|
-
s.currentEntry = { name: entry.name, index: i, bytesIn: entryBytesIn };
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
if (isSyncArchiveSource(entry.source)) {
|
|
173
|
-
const bytes = toUint8ArraySync(entry.source);
|
|
174
|
-
throwIfAborted(signal);
|
|
175
|
-
onChunk(bytes);
|
|
176
|
-
await file.push(bytes, true);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
for await (const chunk of toAsyncIterable(entry.source, { signal, onChunk })) {
|
|
180
|
-
throwIfAborted(signal);
|
|
181
|
-
await file.push(chunk, false);
|
|
182
|
-
}
|
|
183
|
-
throwIfAborted(signal);
|
|
184
|
-
await file.push(new Uint8Array(0), true);
|
|
185
|
-
}
|
|
186
|
-
await file.complete();
|
|
187
|
-
progress.set("entriesDone", progress.snapshot.entriesDone + 1);
|
|
188
|
-
}
|
|
94
|
+
}, { signal: signalOpt, onProgress, progressIntervalMs }, async ({ zip, signal, progress }) => {
|
|
95
|
+
for (let i = 0; i < this._entries.length; i++) {
|
|
189
96
|
throwIfAborted(signal);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
97
|
+
const entry = this._entries[i];
|
|
98
|
+
let entryBytesIn = 0;
|
|
99
|
+
progress.update({ currentEntry: { name: entry.name, index: i, bytesIn: 0 } });
|
|
100
|
+
const file = new ZipDeflateFile(entry.name, buildZipDeflateFileOptions(entry.options, {
|
|
101
|
+
level: this._options.level,
|
|
102
|
+
modTime: this._options.modTime,
|
|
103
|
+
timestamps: this._options.timestamps,
|
|
104
|
+
smartStore: this._options.smartStore,
|
|
105
|
+
zip64: this._options.zip64,
|
|
106
|
+
path: this._options.path,
|
|
107
|
+
encoding: this._options.encoding
|
|
108
|
+
}));
|
|
109
|
+
zip.add(file);
|
|
110
|
+
const onChunk = (chunk) => {
|
|
111
|
+
entryBytesIn += chunk.length;
|
|
112
|
+
progress.mutate(s => {
|
|
113
|
+
s.bytesIn += chunk.length;
|
|
114
|
+
s.currentEntry = { name: entry.name, index: i, bytesIn: entryBytesIn };
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
if (isSyncArchiveSource(entry.source)) {
|
|
118
|
+
const bytes = toUint8ArraySync(entry.source);
|
|
119
|
+
throwIfAborted(signal);
|
|
120
|
+
onChunk(bytes);
|
|
121
|
+
await file.push(bytes, true);
|
|
202
122
|
}
|
|
203
123
|
else {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
signal.removeEventListener("abort", onAbort);
|
|
211
|
-
}
|
|
212
|
-
catch {
|
|
213
|
-
// ignore
|
|
124
|
+
for await (const chunk of toAsyncIterable(entry.source, { signal, onChunk })) {
|
|
125
|
+
throwIfAborted(signal);
|
|
126
|
+
await file.push(chunk, false);
|
|
127
|
+
}
|
|
128
|
+
throwIfAborted(signal);
|
|
129
|
+
await file.push(new Uint8Array(0), true);
|
|
214
130
|
}
|
|
215
|
-
|
|
216
|
-
progress.
|
|
131
|
+
await file.complete();
|
|
132
|
+
progress.set("entriesDone", progress.snapshot.entriesDone + 1);
|
|
217
133
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
signal,
|
|
222
|
-
abort(reason) {
|
|
223
|
-
controller.abort(reason);
|
|
224
|
-
},
|
|
225
|
-
pointer() {
|
|
226
|
-
return progress.snapshot.bytesOut;
|
|
227
|
-
},
|
|
228
|
-
progress() {
|
|
229
|
-
return progress.snapshotCopy();
|
|
230
|
-
}
|
|
231
|
-
};
|
|
134
|
+
throwIfAborted(signal);
|
|
135
|
+
zip.end();
|
|
136
|
+
});
|
|
232
137
|
}
|
|
233
138
|
/**
|
|
234
139
|
* Browser-only fast path: stream sources through CompressionStream while
|
|
@@ -443,6 +348,3 @@ export class ZipArchive {
|
|
|
443
348
|
await pipeIterableToSink(this.stream(options), sink);
|
|
444
349
|
}
|
|
445
350
|
}
|
|
446
|
-
export function createZipArchive(options) {
|
|
447
|
-
return new ZipArchive(options);
|
|
448
|
-
}
|