37 class QuaZipFilePrivate {
41 Q_DISABLE_COPY(QuaZipFilePrivate)
59 quint64 uncompressedSize;
71 inline void resetZipError()
const { setZipError(
UNZ_OK); }
78 void setZipError(
int zipError)
const;
83 caseSensitivity(
QuaZip::csDefault),
91 inline QuaZipFilePrivate(
QuaZipFile *q,
const QString &zipName)
93 caseSensitivity(
QuaZip::csDefault),
100 zip =
new QuaZip(zipName);
104 const QString &zipName,
105 const QString &fileName,
114 zip =
new QuaZip(zipName);
115 this->fileName = fileName;
116 if (this->fileName.startsWith(
'/'))
117 this->fileName = this->fileName.mid(1);
118 this->caseSensitivity = cs;
131 inline ~QuaZipFilePrivate() {
132 if (
internal)
delete zip;
139 : QIODevice(parent), p(new QuaZipFilePrivate(this)) {}
142 : QIODevice(parent), p(new QuaZipFilePrivate(this, zipName)) {}
145 const QString &fileName,
149 p(new QuaZipFilePrivate(this, zipName, fileName, cs)) {}
152 : QIODevice(parent), p(new QuaZipFilePrivate(this, zip)) {}
160 return p->zip ==
NULL ? QString() : p->zip->getZipName();
167 if (p->zip ==
NULL || (openMode() & WriteOnly))
return QString();
168 QString
name = p->zip->getCurrentFileName();
169 if (
name.isNull()) p->setZipError(p->zip->getZipError());
176 "QuaZipFile::setZipName(): file is already open - can not set "
180 if (p->zip !=
NULL && p->internal)
delete p->zip;
181 p->zip =
new QuaZip(zipName);
188 "QuaZipFile::setZip(): file is already open - can not set ZIP");
191 if (p->zip !=
NULL && p->internal)
delete p->zip;
193 p->fileName = QString();
199 if (p->zip ==
NULL) {
200 qWarning(
"QuaZipFile::setFileName(): call setZipName() first");
205 "QuaZipFile::setFileName(): should not be used when not using "
211 "QuaZipFile::setFileName(): can not set file name for already "
215 p->fileName = fileName;
216 if (p->fileName.startsWith(
'/')) p->fileName = p->fileName.mid(1);
217 p->caseSensitivity = cs;
220 void QuaZipFilePrivate::setZipError(
int zipError)
const {
221 QuaZipFilePrivate *fakeThis =
222 const_cast<QuaZipFilePrivate *
>(
this);
223 fakeThis->zipError = zipError;
225 q->setErrorString(QString());
228 QuaZipFile::tr(
"ZIP/UNZIP API error %1").arg(zipError));
237 const char *password) {
240 qWarning(
"QuaZipFile::open(): already opened");
243 if (mode & Unbuffered) {
244 qWarning(
"QuaZipFile::open(): Unbuffered mode is not supported");
247 if ((mode & ReadOnly) && !(mode & WriteOnly)) {
250 p->setZipError(p->zip->getZipError());
253 if (!p->zip->setCurrentFile(p->fileName, p->caseSensitivity)) {
254 p->setZipError(p->zip->getZipError());
259 if (p->zip ==
NULL) {
260 qWarning(
"QuaZipFile::open(): zip is NULL");
265 "QuaZipFile::open(): file open mode %d incompatible "
266 "with ZIP open mode %d",
267 (
int)mode, (
int)p->zip->getMode());
270 if (!p->zip->hasCurrentFile()) {
271 qWarning(
"QuaZipFile::open(): zip does not have current file");
276 (
int)raw, password));
277 if (p->zipError ==
UNZ_OK) {
284 qWarning(
"QuaZipFile::open(): open mode %d not supported by this function",
291 const char *password,
302 qWarning(
"QuaZipFile::open(): already opened");
305 if ((mode & WriteOnly) && !(mode & ReadOnly)) {
308 "QuaZipFile::open(): write mode is incompatible with "
309 "internal QuaZip approach");
312 if (p->zip ==
NULL) {
313 qWarning(
"QuaZipFile::open(): zip is NULL");
320 "QuaZipFile::open(): file open mode %d incompatible with "
322 (
int)mode, (
int)p->zip->getMode());
334 if (p->zip->isDataDescriptorWritingEnabled())
339 p->zip->getZipFile(),
340 p->zip->getFileNameCodec()->fromUnicode(info.
name).constData(),
343 p->zip->getCommentCodec()
346 method, level, (
int)raw, windowBits, memLevel, strategy,
347 password, (uLong)crc, p->zip->isZip64Enabled()));
348 if (p->zipError ==
UNZ_OK) {
360 qWarning(
"QuaZipFile::open(): open mode %d not supported by this function",
368 if (p->zip ==
NULL) {
369 qWarning(
"QuaZipFile::pos(): call setZipName() or setZip() first");
373 qWarning(
"QuaZipFile::pos(): file is not open");
376 if (openMode() & ReadOnly)
380 return unztell64(p->zip->getUnzFile()) - QIODevice::bytesAvailable();
386 if (p->zip ==
NULL) {
387 qWarning(
"QuaZipFile::atEnd(): call setZipName() or setZip() first");
391 qWarning(
"QuaZipFile::atEnd(): file is not open");
394 if (openMode() & ReadOnly)
396 return QIODevice::bytesAvailable() == 0 &&
397 unzeof(p->zip->getUnzFile()) == 1;
404 qWarning(
"QuaZipFile::atEnd(): file is not open");
407 if (openMode() & ReadOnly)
419 if (p->zipError !=
UNZ_OK)
return -1;
429 if (p->zipError !=
UNZ_OK)
return -1;
445 p->zip->getCurrentFileInfo(info);
446 p->setZipError(p->zip->getZipError());
447 return p->zipError ==
UNZ_OK;
452 if (p->zip ==
NULL || !p->zip->isOpen())
return;
454 qWarning(
"QuaZipFile::close(): file isn't open");
457 if (openMode() & ReadOnly)
459 else if (openMode() & WriteOnly)
462 p->uncompressedSize, p->crc));
466 qWarning(
"Wrong open mode: %d", (
int)openMode());
469 if (p->zipError ==
UNZ_OK)
470 setOpenMode(QIODevice::NotOpen);
475 p->setZipError(p->zip->getZipError());
484 p->setZipError((
int)bytesRead);
494 if (p->zipError !=
ZIP_OK)
497 p->writePos += maxSize;
505 return p->caseSensitivity;
A file inside ZIP archive.
bool isRaw() const
Returns true if the file was opened in raw mode.
void setFileName(const QString &fileName, QuaZip::CaseSensitivity cs=QuaZip::csDefault)
Sets the file name.
virtual void close()
Closes the file.
virtual bool open(OpenMode mode)
Opens a file for reading.
QString getActualFileName() const
Returns the actual file name in the archive.
virtual bool isSequential() const
Returns true, but beware!
int getZipError() const
Returns the error code returned by the last ZIP/UNZIP API call.
QString getZipName() const
Returns the ZIP archive file name.
virtual qint64 size() const
Returns file size.
qint64 csize() const
Returns compressed file size.
virtual ~QuaZipFile()
Destroys a QuaZipFile instance.
qint64 readData(char *data, qint64 maxSize)
Implementation of the QIODevice::readData().
virtual bool atEnd() const
Returns true if the end of file was reached.
virtual qint64 bytesAvailable() const
Returns the number of bytes available for reading.
void setZip(QuaZip *zip)
Binds to the existing QuaZip instance.
qint64 writeData(const char *data, qint64 maxSize)
Implementation of the QIODevice::writeData().
QuaZip * getZip() const
Returns a pointer to the associated QuaZip object.
void setZipName(const QString &zipName)
Sets the ZIP archive file name.
virtual qint64 pos() const
Returns current position in the file.
QuaZipFile()
Constructs a QuaZipFile instance.
bool getFileInfo(QuaZipFileInfo *info)
Gets information about current file.
QString getFileName() const
Returns file name.
qint64 usize() const
Returns uncompressed file size.
QuaZip::CaseSensitivity getCaseSensitivity() const
Returns case sensitivity of the file name.
@ mdAdd
ZIP file was opened for adding files in the archive.
@ mdCreate
ZIP file was created with open() call.
@ mdUnzip
ZIP file is open for reading files inside it.
CaseSensitivity
Case sensitivity for the file names.
Information about a file inside archive (with zip64 support).
bool toQuaZipFileInfo(QuaZipFileInfo &info) const
Converts to QuaZipFileInfo.
Information about a file inside archive.
Information about a file to be created.
ulong uncompressedSize
Uncompressed file size.
quint16 internalAttr
File internal attributes.
QByteArray extraLocal
File local extra field.
QByteArray extraGlobal
File global extra field.
QString comment
File comment.
QDateTime dateTime
File timestamp.
quint32 externalAttr
File external attributes.
ZPOS64_T uncompressed_size
ZPOS64_T ZEXPORT unztell64(unzFile file)
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
int ZEXPORT unzeof(unzFile file)
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
int ZEXPORT unzCloseCurrentFile(unzFile file)
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
int ZEXPORT zipSetFlags(zipFile file, unsigned flags)
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting, int zip64)
int ZEXPORT zipCloseFileInZip(zipFile file)
int ZEXPORT zipClearFlags(zipFile file, unsigned flags)
#define ZIP_WRITE_DATA_DESCRIPTOR