ckb-next
v0.2.8 at branch master
ckb-next driver for corsair devices
|
A file inside ZIP archive. More...
#include <quazip/quazipfile.h>
Public Member Functions | |
QuaZipFile () | |
Constructs a QuaZipFile instance. More... | |
QuaZipFile (QObject *parent) | |
Constructs a QuaZipFile instance. More... | |
QuaZipFile (const QString &zipName, QObject *parent=NULL) | |
Constructs a QuaZipFile instance. More... | |
QuaZipFile (const QString &zipName, const QString &fileName, QuaZip::CaseSensitivity cs=QuaZip::csDefault, QObject *parent=NULL) | |
Constructs a QuaZipFile instance. More... | |
QuaZipFile (QuaZip *zip, QObject *parent=NULL) | |
Constructs a QuaZipFile instance. More... | |
virtual | ~QuaZipFile () |
Destroys a QuaZipFile instance. More... | |
QString | getZipName () const |
Returns the ZIP archive file name. More... | |
QuaZip * | getZip () const |
Returns a pointer to the associated QuaZip object. More... | |
QString | getFileName () const |
Returns file name. More... | |
QuaZip::CaseSensitivity | getCaseSensitivity () const |
Returns case sensitivity of the file name. More... | |
QString | getActualFileName () const |
Returns the actual file name in the archive. More... | |
void | setZipName (const QString &zipName) |
Sets the ZIP archive file name. More... | |
bool | isRaw () const |
Returns true if the file was opened in raw mode. More... | |
void | setZip (QuaZip *zip) |
Binds to the existing QuaZip instance. More... | |
void | setFileName (const QString &fileName, QuaZip::CaseSensitivity cs=QuaZip::csDefault) |
Sets the file name. More... | |
virtual bool | open (OpenMode mode) |
Opens a file for reading. More... | |
bool | open (OpenMode mode, const char *password) |
Opens a file for reading. More... | |
bool | open (OpenMode mode, int *method, int *level, bool raw, const char *password=NULL) |
Opens a file for reading. More... | |
bool | open (OpenMode mode, const QuaZipNewInfo &info, const char *password=NULL, quint32 crc=0, int method=Z_DEFLATED, int level=Z_DEFAULT_COMPRESSION, bool raw=false, int windowBits=-MAX_WBITS, int memLevel=MAX_MEM_LEVEL, int strategy=Z_DEFAULT_STRATEGY) |
Opens a file for writing. More... | |
virtual bool | isSequential () const |
Returns true , but beware! More... | |
virtual qint64 | pos () const |
Returns current position in the file. More... | |
virtual bool | atEnd () const |
Returns true if the end of file was reached. More... | |
virtual qint64 | size () const |
Returns file size. More... | |
qint64 | csize () const |
Returns compressed file size. More... | |
qint64 | usize () const |
Returns uncompressed file size. More... | |
bool | getFileInfo (QuaZipFileInfo *info) |
Gets information about current file. More... | |
bool | getFileInfo (QuaZipFileInfo64 *info) |
Gets information about current file with zip64 support. More... | |
virtual void | close () |
Closes the file. More... | |
int | getZipError () const |
Returns the error code returned by the last ZIP/UNZIP API call. More... | |
virtual qint64 | bytesAvailable () const |
Returns the number of bytes available for reading. More... | |
Protected Member Functions | |
qint64 | readData (char *data, qint64 maxSize) |
Implementation of the QIODevice::readData(). More... | |
qint64 | writeData (const char *data, qint64 maxSize) |
Implementation of the QIODevice::writeData(). More... | |
Private Member Functions | |
QuaZipFile (const QuaZipFile &that) | |
QuaZipFile & | operator= (const QuaZipFile &that) |
Private Attributes | |
QuaZipFilePrivate * | p |
Friends | |
class | QuaZipFilePrivate |
This is the most interesting class. Not only it provides C++ interface to the ZIP/UNZIP package, but also integrates it with Qt by subclassing QIODevice. This makes possible to access files inside ZIP archive using QTextStream or QDataStream, for example. Actually, this is the main purpose of the whole QuaZIP library.
You can either use existing QuaZip instance to create instance of this class or pass ZIP archive file name to this class, in which case it will create internal QuaZip object. See constructors' descriptions for details. Writing is only possible with the existing instance.
Note that due to the underlying library's limitation it is not possible to use multiple QuaZipFile instances to open several files in the same archive at the same time. If you need to write to multiple files in parallel, then you should write to temporary files first, then pack them all at once when you have finished writing. If you need to read multiple files inside the same archive in parallel, you should extract them all into a temporary directory first.
At the first thought, QuaZipFile has fixed size, the start and the end and should be therefore considered random-access device. But there is one major obstacle to making it random-access: ZIP/UNZIP API does not support seek() operation and the only way to implement it is through reopening the file and re-reading to the required position, but this is prohibitively slow.
Therefore, QuaZipFile is considered to be a sequential device. This has advantage of availability of the ungetChar() operation (QIODevice does not implement it properly for non-sequential devices unless they support seek()). Disadvantage is a somewhat strange behaviour of the size() and pos() functions. This should be kept in mind while using this class.
Definition at line 74 of file quazipfile.h.
|
private |
QuaZipFile::QuaZipFile | ( | ) |
You should use setZipName() and setFileName() or setZip() before trying to call open() on the constructed object.
Definition at line 108 of file quazipfile.cpp.
QuaZipFile::QuaZipFile | ( | QObject * | parent | ) |
parent argument specifies this object's parent object.
You should use setZipName() and setFileName() or setZip() before trying to call open() on the constructed object.
Definition at line 113 of file quazipfile.cpp.
QuaZipFile::QuaZipFile | ( | const QString & | zipName, |
QObject * | parent = NULL |
||
) |
parent argument specifies this object's parent object and zipName specifies ZIP archive file name.
You should use setFileName() before trying to call open() on the constructed object.
QuaZipFile constructed by this constructor can be used for read only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
Definition at line 119 of file quazipfile.cpp.
QuaZipFile::QuaZipFile | ( | const QString & | zipName, |
const QString & | fileName, | ||
QuaZip::CaseSensitivity | cs = QuaZip::csDefault , |
||
QObject * | parent = NULL |
||
) |
parent argument specifies this object's parent object, zipName specifies ZIP archive file name and fileName and cs specify a name of the file to open inside archive.
QuaZipFile constructed by this constructor can be used for read only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
Definition at line 125 of file quazipfile.cpp.
parent argument specifies this object's parent object.
zip is the pointer to the existing QuaZip object. This QuaZipFile object then can be used to read current file in the zip or to write to the file inside it.
zip
archive, file
that references it becomes invalid (actually, as far as I understand ZIP/UNZIP sources, it becomes closed, but QuaZipFile has no means to detect it).Summary: do not close zip
object or change its current file as long as QuaZipFile is open. Even better - use another constructors which create internal QuaZip instances, one per object, and therefore do not cause unnecessary trouble. This constructor may be useful, though, if you already have a QuaZip instance and do not want to access several files at once. Good example:
Definition at line 132 of file quazipfile.cpp.
|
virtual |
Closes file if open, destructs internal QuaZip object (if it exists and is internal, of course).
Definition at line 138 of file quazipfile.cpp.
|
virtual |
This function returns false
in the case of error. This means that you called this function on either not open file, or a file in the not open archive or even on a QuaZipFile instance that does not even have QuaZip instance associated. Do not do that because there is no means to determine whether false
is returned because of error or because end of file was reached. Well, on the other side you may interpret false
return value as "there is no file open to check for end of file and there is
no end of file therefore".
When writing, this function always returns true
(because you are always writing to the end of file).
Error code returned by getZipError() is not affected by this function call.
Definition at line 361 of file quazipfile.cpp.
References QuaZip::getUnzFile(), p, unzeof(), and QuaZipFilePrivate::zip.
|
virtual |
Definition at line 499 of file quazipfile.cpp.
|
virtual |
Call getZipError() to determine if the close was successful.
Definition at line 432 of file quazipfile.cpp.
References QuaZip::close(), QuaZipFilePrivate::crc, QuaZip::getUnzFile(), QuaZip::getZipError(), QuaZip::getZipFile(), QuaZipFilePrivate::internal, QuaZip::isOpen(), isRaw(), p, QuaZipFilePrivate::resetZipError(), QuaZipFilePrivate::setZipError(), QuaZipFilePrivate::uncompressedSize, UNZ_OK, unzCloseCurrentFile(), QuaZipFilePrivate::zip, zipCloseFileInZip(), zipCloseFileInZipRaw64(), and QuaZipFilePrivate::zipError.
Referenced by JlCompress::compressFile(), JlCompress::compressSubDir(), JlCompress::extractFile(), and ~QuaZipFile().
qint64 QuaZipFile::csize | ( | ) | const |
Equivalent to calling getFileInfo() and then getting compressedSize field, but more convenient and faster.
File must be open for reading before calling this function.
Returns -1 on error, call getZipError() to get error code.
Definition at line 391 of file quazipfile.cpp.
References unz_file_info64_s::compressed_size, QuaZip::getMode(), QuaZip::getUnzFile(), QuaZip::mdUnzip, p, QuaZipFilePrivate::setZipError(), UNZ_OK, unzGetCurrentFileInfo64(), QuaZipFilePrivate::zip, and QuaZipFilePrivate::zipError.
Referenced by size().
QString QuaZipFile::getActualFileName | ( | ) | const |
This is not a ZIP archive file name, but a name of file inside archive. It is not necessary the same name that you have passed to the QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*), setFileName() or QuaZip::setCurrentFile() - this is the real file name inside archive, so it may differ in case if the file name search was case-insensitive.
Equivalent to calling getCurrentFileName() on the associated QuaZip object. Returns null string if there is no associated QuaZip object or if it does not have a current file yet. And this is the case if you called setFileName() but did not open the file yet. So this is perfectly fine:
Definition at line 155 of file quazipfile.cpp.
References QuaZip::getCurrentFileName(), QuaZip::getZipError(), p, QuaZipFilePrivate::setZipError(), UNZ_OK, and QuaZipFilePrivate::zip.
QuaZip::CaseSensitivity QuaZipFile::getCaseSensitivity | ( | ) | const |
This function returns case sensitivity argument you passed to this object either by using QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*) or by calling setFileName().
Returns unpredictable value if getFileName() returns null string (this is the case when you did not used setFileName() or constructor above).
Definition at line 484 of file quazipfile.cpp.
References QuaZipFilePrivate::caseSensitivity, and p.
bool QuaZipFile::getFileInfo | ( | QuaZipFileInfo * | info | ) |
This function does the same thing as calling QuaZip::getCurrentFileInfo() on the associated QuaZip object, but you can not call getCurrentFileInfo() if the associated QuaZip is internal (because you do not have access to it), while you still can call this function in that case.
File must be open for reading before calling this function.
false
in the case of an error.This function doesn't support zip64, but will still work fine on zip64 archives if file sizes are below 4 GB, otherwise the values will be set as if converted using QuaZipFileInfo64::toQuaZipFileInfo().
Definition at line 413 of file quazipfile.cpp.
References QuaZipFileInfo64::toQuaZipFileInfo().
bool QuaZipFile::getFileInfo | ( | QuaZipFileInfo64 * | info | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 424 of file quazipfile.cpp.
References QuaZip::getCurrentFileInfo(), QuaZip::getMode(), QuaZip::getZipError(), QuaZip::mdUnzip, p, QuaZipFilePrivate::setZipError(), UNZ_OK, QuaZipFilePrivate::zip, and QuaZipFilePrivate::zipError.
QString QuaZipFile::getFileName | ( | ) | const |
This function returns file name you passed to this object either by using QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*) or by calling setFileName(). Real name of the file may differ in case if you used case-insensitivity.
Returns null string if there is no file name set yet. This is the case when this QuaZipFile operates on the existing QuaZip object (constructor QuaZipFile(QuaZip*,QObject*) or setZip() was used).
Definition at line 479 of file quazipfile.cpp.
References QuaZipFilePrivate::fileName, and p.
QuaZip * QuaZipFile::getZip | ( | ) | const |
Returns NULL
if there is no associated QuaZip or it is internal (so you will not mess with it).
Definition at line 150 of file quazipfile.cpp.
References QuaZipFilePrivate::internal, p, and QuaZipFilePrivate::zip.
int QuaZipFile::getZipError | ( | ) | const |
Definition at line 494 of file quazipfile.cpp.
References p, and QuaZipFilePrivate::zipError.
Referenced by JlCompress::compressFile(), and JlCompress::extractFile().
QString QuaZipFile::getZipName | ( | ) | const |
If this object was created by passing QuaZip pointer to the constructor, this function will return that QuaZip's file name (or null string if that object does not have file name yet).
Otherwise, returns associated ZIP archive file name or null string if there are no name set yet.
Definition at line 145 of file quazipfile.cpp.
References QuaZip::getZipName(), p, and QuaZipFilePrivate::zip.
bool QuaZipFile::isRaw | ( | ) | const |
If the file is not open, the returned value is undefined.
Definition at line 489 of file quazipfile.cpp.
References p, and QuaZipFilePrivate::raw.
Referenced by close().
|
virtual |
Definition at line 337 of file quazipfile.cpp.
|
virtual |
Returns true
on success, false
otherwise. Call getZipError() to get error code.
Definition at line 221 of file quazipfile.cpp.
Referenced by KbFirmware::_fileForBoard(), JlCompress::compressFile(), JlCompress::compressSubDir(), and JlCompress::extractFile().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Argument password specifies a password to decrypt the file. If it is NULL then this function behaves just like open(OpenMode).
Definition at line 298 of file quazipfile.h.
bool QuaZipFile::open | ( | OpenMode | mode, |
int * | method, | ||
int * | level, | ||
bool | raw, | ||
const char * | password = NULL |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Argument password specifies a password to decrypt the file.
An integers pointed by method and level will receive codes of the compression method and level used. See unzip.h.
If raw is true
then no decompression is performed.
method should not be NULL
. level can be NULL
if you don't want to know the compression level.
Definition at line 226 of file quazipfile.cpp.
References QuaZipFilePrivate::caseSensitivity, QuaZip::close(), QuaZipFilePrivate::fileName, QuaZip::getMode(), QuaZip::getUnzFile(), QuaZip::getZipError(), QuaZip::hasCurrentFile(), QuaZipFilePrivate::internal, QuaZip::mdUnzip, QuaZip::open(), p, QuaZipFilePrivate::raw, QuaZipFilePrivate::resetZipError(), QuaZip::setCurrentFile(), QuaZipFilePrivate::setZipError(), UNZ_OK, unzOpenCurrentFile3(), QuaZipFilePrivate::zip, and QuaZipFilePrivate::zipError.
bool QuaZipFile::open | ( | OpenMode | mode, |
const QuaZipNewInfo & | info, | ||
const char * | password = NULL , |
||
quint32 | crc = 0 , |
||
int | method = Z_DEFLATED , |
||
int | level = Z_DEFAULT_COMPRESSION , |
||
bool | raw = false , |
||
int | windowBits = -MAX_WBITS , |
||
int | memLevel = MAX_MEM_LEVEL , |
||
int | strategy = Z_DEFAULT_STRATEGY |
||
) |
info argument specifies information about file. It should at least specify a correct file name. Also, it is a good idea to specify correct timestamp (by default, current time will be used). See QuaZipNewInfo.
The password argument specifies the password for crypting. Pass NULL if you don't need any crypting. The crc argument was supposed to be used for crypting too, but then it turned out that it's false information, so you need to set it to 0 unless you want to use the raw mode (see below).
Arguments method and level specify compression method and level. The only method supported is Z_DEFLATED, but you may also specify 0 for no compression. If all of the files in the archive use both method 0 and either level 0 is explicitly specified or data descriptor writing is disabled with QuaZip::setDataDescriptorWritingEnabled(), then the resulting archive is supposed to be compatible with the 1.0 ZIP format version, should you need that. Except for this, level has no other effects with method 0.
If raw is true
, no compression is performed. In this case, crc and uncompressedSize field of the info are required.
Arguments windowBits, memLevel, strategy provide zlib algorithms tuning. See deflateInit2() in zlib.
Definition at line 275 of file quazipfile.cpp.
References QuaZipNewInfo::comment, QuaZipFilePrivate::crc, QuaZipNewInfo::dateTime, zip_fileinfo::dosDate, zip_fileinfo::external_fa, QuaZipNewInfo::externalAttr, QuaZipNewInfo::extraGlobal, QuaZipNewInfo::extraLocal, QuaZip::getCommentCodec(), QuaZip::getFileNameCodec(), QuaZip::getMode(), QuaZip::getZipFile(), QuaZipFilePrivate::internal, zip_fileinfo::internal_fa, QuaZipNewInfo::internalAttr, QuaZip::isDataDescriptorWritingEnabled(), QuaZip::isZip64Enabled(), QuaZip::mdAdd, QuaZip::mdAppend, QuaZip::mdCreate, QuaZipNewInfo::name, p, QuaZipFilePrivate::raw, QuaZipFilePrivate::resetZipError(), QuaZipFilePrivate::setZipError(), tm_zip_s::tm_hour, tm_zip_s::tm_mday, tm_zip_s::tm_min, tm_zip_s::tm_mon, tm_zip_s::tm_sec, tm_zip_s::tm_year, zip_fileinfo::tmz_date, QuaZipFilePrivate::uncompressedSize, QuaZipNewInfo::uncompressedSize, UNZ_OK, QuaZipFilePrivate::writePos, QuaZipFilePrivate::zip, ZIP_WRITE_DATA_DESCRIPTOR, zipClearFlags(), QuaZipFilePrivate::zipError, zipOpenNewFileInZip3_64(), and zipSetFlags().
|
private |
|
virtual |
Implementation of the QIODevice::pos(). When reading, this function is a wrapper to the ZIP/UNZIP unztell(), therefore it is unable to keep track of the ungetChar() calls (which is non-virtual and therefore is dangerous to reimplement). So if you are using ungetChar() feature of the QIODevice, this function reports incorrect value until you get back characters which you ungot.
When writing, pos() returns number of bytes already written (uncompressed unless you use raw mode).
This function returns -1 if the file or archive is not open.
Error code returned by getZipError() is not affected by this function call.
Definition at line 342 of file quazipfile.cpp.
References QuaZip::getUnzFile(), p, unztell(), QuaZipFilePrivate::writePos, and QuaZipFilePrivate::zip.
Referenced by bytesAvailable().
|
protected |
Definition at line 457 of file quazipfile.cpp.
References QuaZip::getUnzFile(), p, QuaZipFilePrivate::setZipError(), UNZ_OK, unzReadCurrentFile(), and QuaZipFilePrivate::zip.
void QuaZipFile::setFileName | ( | const QString & | fileName, |
QuaZip::CaseSensitivity | cs = QuaZip::csDefault |
||
) |
Will do nothing if at least one of the following conditions is met:
Definition at line 191 of file quazipfile.cpp.
References QuaZipFilePrivate::caseSensitivity, QuaZipFilePrivate::fileName, QuaZipFilePrivate::internal, p, and QuaZipFilePrivate::zip.
void QuaZipFile::setZip | ( | QuaZip * | zip | ) |
This function destroys internal QuaZip object, if any, and makes this QuaZipFile to use current file in the zip object for any further operations. See QuaZipFile(QuaZip*,QObject*) for the possible pitfalls.
Will do nothing if the file is currently open. You must close() it first.
Definition at line 178 of file quazipfile.cpp.
References QuaZipFilePrivate::fileName, QuaZipFilePrivate::internal, p, and QuaZipFilePrivate::zip.
void QuaZipFile::setZipName | ( | const QString & | zipName | ) |
Automatically creates internal QuaZip object and destroys previously created internal QuaZip object, if any.
Will do nothing if this file is already open. You must close() it first.
Definition at line 166 of file quazipfile.cpp.
References QuaZipFilePrivate::internal, p, and QuaZipFilePrivate::zip.
|
virtual |
This function returns csize() if the file is open for reading in raw mode, usize() if it is open for reading in normal mode and pos() if it is open for writing.
Returns -1 on error, call getZipError() to get error code.
Definition at line 379 of file quazipfile.cpp.
References csize(), p, QuaZipFilePrivate::raw, usize(), and QuaZipFilePrivate::writePos.
Referenced by bytesAvailable().
qint64 QuaZipFile::usize | ( | ) | const |
Equivalent to calling getFileInfo() and then getting uncompressedSize field, but more convenient and faster. See getFileInfo() for a warning.
File must be open for reading before calling this function.
Returns -1 on error, call getZipError() to get error code.
Definition at line 402 of file quazipfile.cpp.
References QuaZip::getMode(), QuaZip::getUnzFile(), QuaZip::mdUnzip, p, QuaZipFilePrivate::setZipError(), unz_file_info64_s::uncompressed_size, UNZ_OK, unzGetCurrentFileInfo64(), QuaZipFilePrivate::zip, and QuaZipFilePrivate::zipError.
Referenced by size().
|
protected |
Definition at line 468 of file quazipfile.cpp.
References QuaZip::getZipFile(), p, QuaZipFilePrivate::setZipError(), QuaZipFilePrivate::writePos, QuaZipFilePrivate::zip, ZIP_OK, QuaZipFilePrivate::zipError, and zipWriteInFileInZip().
|
friend |
Definition at line 75 of file quazipfile.h.
|
private |
Definition at line 78 of file quazipfile.h.
Referenced by atEnd(), close(), csize(), getActualFileName(), getCaseSensitivity(), getFileInfo(), getFileName(), getZip(), getZipError(), getZipName(), isRaw(), open(), pos(), readData(), setFileName(), setZip(), setZipName(), size(), usize(), writeData(), and ~QuaZipFile().