ArcGIS for Developers

ZipReader QML Type

Extract a zip file and read extracted files. More...

Import Statement: import ArcGIS.AppFramework 1.0
Inherits:

AppFrameworkObject

Properties

Signals

  • completed()
  • error( string fileName, string outputFileName, Result result)
  • progress( string fileName, string outputFileName, double percent)

Methods

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.

NameValue
ZipReader.CrcError-105
ZipReader.InternalError-104
ZipReader.BadZipFile-103
ZipReader.ParameterError-102
ZipReader.EndOfListOfFile-100
ZipReader.ErrNo-1
ZipReader.EndOfFile0

Property Documentation

caseSensitive : bool

True if the archived zip's filename is case sensitive. Otherwise, appears as false.


[read-only] fileNames : QStringList

Returns a list of files within the archived zip file. This also includes filename of the files within folders inside the archive.


[read-only] folderNames : QStringList

Returns the list of folders and subfolders within the archived zip file.


[read-only] isOpen : string

Returns an empty string if the zip archive is closed.


path : string

The path to the archived zip file. For example, "C:\testingZipWriter\zipwriterfile.zip"


Signal Documentation

completed()

Signal emitted when the contents of the archived has finished being extracted.


error( string fileName, string outputFileName, Result result)

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.


progress( string fileName, string outputFileName, double percent)

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.


Method Documentation

close()

Closes the archived zip file if one is open.


bool exists(fileName)

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"


bool extractAll(outputPath)

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.


bool extractAll(outputPath, string basePath)

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.


bool extractFile(fileName, string outputFilePath)

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(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.


object readJsonFile(fileName)

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"


string readTextFile(fileName)

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"


refresh()

Refresh the contents of the archived zip file.