API: zip
Source:
io/zip.ts
Provides a façade for handling ZIP archive operations, including file compression, decompression, and stream-based entry processing.
Classes
Zip
The Zip class provides static utility methods for managing ZIP archives
at both file path level and stream level.
Methods
zip
zip (sourcePath:string, zipTargetPath:string):voidZips the content of a source directory or file into a target ZIP file.
@param sourcePath The file system path to the content to be compressed.
@param zipTargetPath The file system path where the resulting ZIP file should be saved.
unzip
unzip (zipPath:string, targetPath:string):voidUnzips an existing ZIP file into a target directory.
@param zipPath The file system path to the ZIP file to be extracted.
@param targetPath The file system path to the directory where content should be extracted.
createZipInputStream
createZipInputStream (inputStream:InputStream):ZipInputStreamCreates a {@link ZipInputStream} that reads ZIP archive data from a provided
generic {@link InputStream}. This allows for reading ZIP entries without
writing the archive to disk first.
@param inputStream The source stream containing the raw ZIP data.
@returns A new {@link ZipInputStream} instance.
createZipOutputStream
createZipOutputStream (outputStream:OutputStream):ZipOutputStreamCreates a {@link ZipOutputStream} that writes compressed ZIP archive data
to a provided generic {@link OutputStream}. This allows for creating ZIP archives
in memory or streaming them directly.
@param outputStream The destination stream where the raw ZIP data will be written.
@returns A new {@link ZipOutputStream} instance.
ZipInputStream
Represents an input stream for reading data from a ZIP archive.
Data is accessed sequentially by iterating through {@link ZipEntry} objects.
Methods
getNextEntry
getNextEntry ():ZipEntryReads 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.
@returns The next {@link ZipEntry} object, or null if there are no more entries.
read
read ():any[]Reads the data for the current entry and returns it as a JavaScript byte array.
@returns A JavaScript array (number[]) of the byte values for the current entry.
readNative
readNative ():any[]Reads the data for the current entry and returns the native Java byte array.
@returns The native Java byte array object.
readText
readText ():stringReads the data for the current entry and converts it to a string
using the platform's default character encoding.
@returns The content of the current entry as a string.
close
close ():voidCloses the underlying native ZipInputStream.
ZipOutputStream
Represents an output stream for writing data to a ZIP archive.
Entries must be explicitly created and closed.
Methods
createZipEntry
createZipEntry (name:string):ZipEntryCreates a new {@link 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 {@link closeEntry} is called.
@param name The file or directory name to use inside the ZIP archive.
@returns The newly created {@link ZipEntry} object.
write
write (data:any[]):voidWrites the data from a JavaScript byte array to the current active entry in the stream.
@param data The JavaScript array (number[]) of byte values to write.
writeNative
writeNative (data:any[]):voidWrites the data from a native Java byte array to the current active entry in the stream.
@param data The native Java byte array object to write.
writeText
writeText (text:string):voidConverts the string to bytes and writes it to the current active entry in the stream.
@param text The string content to write.
closeEntry
closeEntry ():voidCloses the current active ZIP entry and positions the stream for the next entry.
close
close ():voidFinalizes the writing of the ZIP file, flushes the stream, and closes the native object.
This must be called after all entries have been written.
ZipEntry
Represents an entry (file or directory) within a ZIP archive.
It holds metadata about the archived item.
Methods
getName
getName ():stringGets the name of the entry (path relative to the ZIP root).
@returns The name of the entry.
getSize
getSize ():numberGets the uncompressed size of the entry data.
@returns The size in bytes.
getCompressedSize
getCompressedSize ():numberGets the compressed size of the entry data.
@returns The compressed size in bytes.
getTime
getTime ():numberGets the modification time of the entry.
@returns The time as a numerical timestamp.
getCrc
getCrc ():numberGets the CRC-32 checksum of the uncompressed entry data.
@returns The CRC value.
getComment
getComment ():stringGets the optional comment for the entry.
@returns The comment string.
isDirectory
isDirectory ():booleanChecks if the entry represents a directory.
@returns True if it is a directory, false otherwise.
isValid
isValid ():booleanChecks if the underlying native ZipEntry object is defined and non-null.
@returns True if the entry is valid, false otherwise.