Extract a zip file and read extracted files. More...
Import Statement: | import ArcGIS.AppFramework 1.0 |
Inherits: |
Properties
- caseSensitive : bool
- fileNames : QStringList
- folderNames : QStringList
- isOpen : bool
- path : string
Signals
- completed()
- error(string fileName, string outputFileName, Result result)
- progress(string fileName, string outputFileName, double percent)
Methods
- close()
- bool exists(string fileName)
- bool extractAll(string outputPath)
- bool extractAll(string outputPath, string basePath)
- bool extractFile(string fileName, string outputFilePath)
- ZipFileInfo fileInfo(string fileName)
- object readJsonFile(string fileName)
- string readTextFile(string fileName)
- refresh()
Detailed Description
The ZipReader component contains tools to read text and JSON files contained within a zip archive, as well as to extract any (or all) files. If information about the files rather than the contents itself is needed, ZipReader can also instantiate the ZipFileInfo component.
The following code sample demonstrates use of the ZipReader component.
App { id: app width: 400 height: 640 ZipReader { id:zipReader path:"C:\\testing\\ZipReader\\testfile.zip" onError: { console.log("Error extracting ", fileName) } onProgress: { if(percent == 0) resultArea.text +="\n" + "****** Extracting Next item ******" +"\n\n" resultArea.text += ("Extracted- %1 file %2 % at %3 ").arg(fileName).arg(percent).arg(outputFileName) + "\n" } onCompleted: { resultArea.text += "\n Extract completed" } } Column { spacing: 10 Text { text:zipReader.path } Button { text:"Click to Extract Zip File" onClicked:{ console.log(zipReader.extractAll("C:\\testing\\new")) } } TextArea { id:resultArea width: app.width height: app.height } } }
Enumerations
Result enumeration
This enum describes the result of the error returned by the Error() signal.
Name | Value |
---|---|
ZipReader.CrcError | -105 |
ZipReader.InternalError | -104 |
ZipReader.BadZipFile | -103 |
ZipReader.ParameterError | -102 |
ZipReader.EndOfListOfFile | -100 |
ZipReader.ErrNo | -1 |
ZipReader.EndOfFile | 0 |
Property Documentation
True if the archived zip's filename is case sensitive. Otherwise, appears as false.
Returns a list of files within the archived zip file. This also includes filename of the files within folders inside the archive.
Returns the list of folders and subfolders within the archived zip file.
The path to the archived zip file. For example, "C:\testing
ZipWriter\zipwriterfile
.zip"
Signal Documentation
Signal emitted when the contents of the archived has finished being extracted.
Note: The corresponding handler is onCompleted
.
Signal emitted when an error has been encountered when reading from the archive. Provides the filename of the file that was unable to be extracted, its intended output filename, and the result of the attempt.
Note: The corresponding handler is onError
.
Signal emitted over the course of the file's extraction, providing progressive information about the file. This includes the filename, its output location, and the percentage of download completed.
Note: The corresponding handler is onProgress
.
Method Documentation
Returns true if a file with the given filename exists. If not, returns false.
The fileName parameter
The filename of the file you're searching for, for example "Bruce.txt"
Attempts to extract all files from the archive to the designated output path, returning true once it has completed. If it is unable to extract the files, will return false.
The outputPath parameter
The output location on the disk where you want the file extracted to.
Attempts to extract all files from the archive to the designated output path, using the basePath parameter as a filter, returning true once it has completed. If it is unable to extract the files, will return false.
The outputPath parameter
The output location on the disk where you want the file extracted to.
The basePath parameter
When this parameter is specified, this method only extracts files and folders from the zip archive that starts with the given basePath. For example, a basePath of 'photos' will extract only the files within the 'photos' folder.
Extract the designated file to the given path.
The fileName parameter
The name of the file to extract from the zip archive.
The outputFilePath parameter
The destination file path for the extracted file.
ZipFileInfo fileInfo(string fileName) |
Returns the ZipFileInfo object of the declared file within the zip archive.
The fileName parameter
The name of the file to return the ZipFileInfo object for.
Returns the content of the designated JSON file as a string.
The fileName parameter
The name of the JSON file within the archived zip file, for example "Bruce.json"
Returns the content of the designated text file as a string.
The fileName parameter
The name of the text file within the archived zip file, for example "Bruce.txt"