SevenZip
7Zip is an open-source file compression library. The DolphinDB SevenZip plugin is developed based on the P7Zip open-source library and supports compression and decompression in various formats:
- Compression: 7z, bzip2, gzip, tar, wim, xz, zip
- Decompression: 7z, bzip2, gzip, tar, wim, xz, zip, rar
Installation (with installPlugin
)
Required server version: DolphinDB 2.00.11 or higher
Supported OS: Windows, Windows JIT, Linux x86, Linux ABI, Linux JIT, and Linux ARM.
Installation Steps:
(1) Use listRemotePlugins to check plugin information in the plugin repository.
Note: For plugins not included in the provided list, you can install through precompiled binaries or compile from source. These files can be accessed from our GitHub repository by switching to the appropriate version branch.
login("admin", "123456")
listRemotePlugins()
(2) Invoke installPlugin for plugin installation.
installPlugin("SevenZip")
(3) Use loadPlugin to load the plugin before using the plugin methods.
loadPlugin("SevenZip")
Method References
unzip
Syntax
unzip(sevenZipFilePath, [outputDir], [password], [callback])
Details
Extract files from a 7Zip archive and process each file using the specified callback function.
Return value: A STRING vector indicating the paths of the extracted files.
Parameters
- sevenZipFilePath: A STRING scalar indicating the path of the 7Zip archive to extract.
- outputDir (optional): A STRING scalar indicating the output directory for the extracted files. If unspecified, files will be extracted to sevenZipFilePath.
- password (optional): A STRING scalar indicating the password for the 7Zip archive.
- callback (optional): A unary function that takes a STRING scalar (path of the extracted files) as input.
Examples
def handler1(filePath){
print(filePath)
}
path = "/hdd1/commit/DolphinDBPlugin"
extractPath = "/hdd1/commit/DolphinDBPlugin/tmp"
SevenZip::unzip(path + "/data.7z", extractPath, "123456", handler1)
zip
Syntax
zip(sevenZipFilePath, fileOrFolderPath, [compressionLevel], [compressionMethod], [password])
Details
Compress a file or folder into a specified 7Zip archive.
Parameters
- sevenZipFilePath: A STRING scalar indicating the path of the 7Zip archive.
- fileOrFolderPath: A STRING scalar indicating the path of the file or folder to compress.
- compressionLevel (optional): An integer indicating the compression level ranging from 1 to 9 (highest). The default value is 5.
- compressionMethod (optional): A STRING scalar indicating the
compression method, which varies by file format.
Format Extension Supported Method 7z 7z LZMA2 (default), LZMA, PPMd, BZip2 bzip2 bzip2, bz2, bzip2, tbz2 Cannot specify compression method. gzip gzip, gz, tgz Cannot specify compression method. tar tar, ova Cannot specify compression method. wim wim, swm, esd Cannot specify compression method. xz xz, txz Cannot specify compression method.。 zip zip01, zipx, jar, xpi, odt, ods, docx, xlsx, epub Deflate (default), Deflate64, BZip2, LZMA, PPMd - password (optional): A STRING scalar indicating the password for the file or folder to compress.
Examples
path = "/hdd1/commit/DolphinDBPlugin"
SevenZip::zip(path + "/data.7z", path + "/7ZipData", 5, "lzma2", "123456")