io/zip
Documentation
- source: io/zip.ts
Overview
Classes
Zip
zip()
Zips the content of a source directory or file into a target ZIP file.
tsstatic zip(sourcePath: string, zipTargetPath: string): void;
Parameter Type Description sourcePathstringThe file system path to the content to be compressed. zipTargetPathstringThe file system path where the resulting ZIP file should be saved. Returns
- Type:
void- Description:
unzip()
Unzips an existing ZIP file into a target directory.
tsstatic unzip(zipPath: string, targetPath: string): void;
Parameter Type Description zipPathstringThe file system path to the ZIP file to be extracted. targetPathstringThe file system path to the directory where content should be extracted. Returns
- Type:
void- Description:
createZipInputStream()
Creates a ZipInputStream that reads ZIP archive data from a provided generic InputStream. This allows for reading ZIP entries without writing the archive to disk first.
tsstatic createZipInputStream(inputStream: InputStream): ZipInputStream;
Parameter Type Description inputStreamInputStreamThe source stream containing the raw ZIP data. Returns
- Type:
ZipInputStream- Description: A new ZipInputStream instance.
createZipOutputStream()
Creates a ZipOutputStream that writes compressed ZIP archive data to a provided generic OutputStream. This allows for creating ZIP archives in memory or streaming them directly.
tsstatic createZipOutputStream(outputStream: OutputStream): ZipOutputStream;
Parameter Type Description outputStreamOutputStreamThe destination stream where the raw ZIP data will be written. Returns
- Type:
ZipOutputStream- Description: A new ZipOutputStream instance.
ZipInputStream
getNextEntry()
Reads the next ZIP file entry and positions the stream at the beginning of the entry data. Must be called before reading data for an entry.
tsgetNextEntry(): ZipEntry;Returns
- Type:
ZipEntry- Description: The next ZipEntry object, or null if there are no more entries.
read()
Reads the data for the current entry and returns it as a JavaScript byte array.
tsread(): void;Returns
- Type:
void- Description: A JavaScript array (`number[]`) of the byte values for the current entry.
readNative()
Reads the data for the current entry and returns the native Java byte array.
tsreadNative(): void;Returns
- Type:
void- Description: The native Java byte array object.
readText()
Reads the data for the current entry and converts it to a string using the platform's default character encoding.
tsreadText(): string;Returns
- Type:
string- Description: The content of the current entry as a string.
close()
Closes the underlying native ZipInputStream.
tsclose(): void;Returns
- Type:
void- Description:
ZipOutputStream
createZipEntry()
Creates a new ZipEntry with the given name, and begins writing the entry's header to the archive stream. All subsequent write operations will apply to this entry until closeEntry is called.
tscreateZipEntry(name: string): ZipEntry;
Parameter Type Description namestringThe file or directory name to use inside the ZIP archive. Returns
- Type:
ZipEntry- Description: The newly created ZipEntry object.
write()
Writes the data from a JavaScript byte array to the current active entry in the stream.
tswrite(data: any): void;
Parameter Type Description dataanyThe JavaScript array (`number[]`) of byte values to write. Returns
- Type:
void- Description:
writeNative()
Writes the data from a native Java byte array to the current active entry in the stream.
tswriteNative(data: any): void;
Parameter Type Description dataanyThe native Java byte array object to write. Returns
- Type:
void- Description:
writeText()
Converts the string to bytes and writes it to the current active entry in the stream.
tswriteText(text: string): void;
Parameter Type Description textstringThe string content to write. Returns
- Type:
void- Description:
closeEntry()
Closes the current active ZIP entry and positions the stream for the next entry.
tscloseEntry(): void;Returns
- Type:
void- Description:
close()
Finalizes the writing of the ZIP file, flushes the stream, and closes the native object. This must be called after all entries have been written.
tsclose(): void;Returns
- Type:
void- Description:
ZipEntry
getName()
Gets the name of the entry (path relative to the ZIP root).
tsgetName(): string;Returns
- Type:
string- Description: The name of the entry.
getSize()
Gets the uncompressed size of the entry data.
tsgetSize(): number;Returns
- Type:
number- Description: The size in bytes.
getCompressedSize()
Gets the compressed size of the entry data.
tsgetCompressedSize(): number;Returns
- Type:
number- Description: The compressed size in bytes.
getTime()
Gets the modification time of the entry.
tsgetTime(): number;Returns
- Type:
number- Description: The time as a numerical timestamp.
getCrc()
Gets the CRC-32 checksum of the uncompressed entry data.
tsgetCrc(): number;Returns
- Type:
number- Description: The CRC value.
getComment()
Gets the optional comment for the entry.
tsgetComment(): string;Returns
- Type:
string- Description: The comment string.
isDirectory()
Checks if the entry represents a directory.
tsisDirectory(): boolean;Returns
- Type:
boolean- Description: True if it is a directory, false otherwise.
isValid()
Checks if the underlying native ZipEntry object is defined and non-null.
tsisValid(): boolean;Returns
- Type:
boolean- Description: True if the entry is valid, false otherwise.
