Commit 188014b2 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Cache writing to the zip file

parent 40715bcc
......@@ -30,6 +30,8 @@
#include <QTemporaryFile>
#include <QTextCodec>
#include <QByteArray>
#include <QBuffer>
#include <KConfig>
#include <KSharedConfig>
......@@ -44,6 +46,8 @@ struct KoQuaZipStore::Private {
QuaZipFile *currentFile {0};
int compressionLevel {Z_DEFAULT_COMPRESSION};
bool usingSaveFile {false};
QByteArray cache;
QBuffer buffer;
};
......@@ -112,7 +116,7 @@ qint64 KoQuaZipStore::write(const char *_data, qint64 _len)
}
d->size += _len;
if (dd->currentFile->write(_data, _len)) { // writeData returns a bool!
if (dd->buffer.write(_data, _len)) { // writeData returns a bool!
return _len;
}
return 0;
......@@ -191,6 +195,11 @@ bool KoQuaZipStore::openWrite(const QString &name)
if (!r) {
qWarning() << "Could not open" << name << dd->currentFile->getZipError();
}
dd->cache = QByteArray();
dd->buffer.setBuffer(&dd->cache);
dd->buffer.open(QBuffer::WriteOnly);
return r;
}
......@@ -230,9 +239,16 @@ bool KoQuaZipStore::openRead(const QString &name)
bool KoQuaZipStore::closeWrite()
{
Q_D(KoStore);
bool r = true;
if (!dd->currentFile->write(dd->cache)) {
qWarning() << "Could not write buffer to the file";
r = false;
}
dd->buffer.close();
dd->currentFile->close();
d->stream = 0;
return dd->currentFile->getZipError() == ZIP_OK;
return (r && dd->currentFile->getZipError() == ZIP_OK);
}
bool KoQuaZipStore::closeRead()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment