[frameworks/karchive] src: kzip: write data in chunks

George Florea Bănuș <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 2cf5f281c3e1995e2941d605a26a5f2c161020ce by George Florea Bănuș.
Committed on 27/07/2026 at 14:35.
Pushed by georgefb into branch 'master'.

kzip: write data in chunks

z_stream::avail_in is a uint32_t and only supports input sizes up to UINT32_MAX

M  +15   -2    src/kzip.cpp

https://invent.kde.org/frameworks/karchive/-/commit/2cf5f281c3e1995e2941d605a26a5f2c161020ce

diff --git a/src/kzip.cpp b/src/kzip.cpp
index 27e0a2c..d16ee76 100644
--- a/src/kzip.cpp
+++ b/src/kzip.cpp
@@ -1528,9 +1528,22 @@ bool KZip::doWriteData(const char *data, qint64 size)
     // and they didn't mention it in their docs...
     d->m_crc = crc32(d->m_crc, (const Bytef *)data, size);
 
-    qint64 written = d->m_currentDev->write(data, size);
+    constexpr qint64 chunkSize = 2 * 1024 * 1024;
+    qint64 totalWritten = 0;
+    while (totalWritten < size) {
+        qint64 chunk = std::min(chunkSize, size - totalWritten);
+
+        qint64 currentWritten = d->m_currentDev->write(data + totalWritten, chunk);
+        if (currentWritten != chunk) {
+            setErrorString(tr("Error writing data chunk: %1").arg(d->m_currentDev->errorString()));
+            return false;
+        }
+
+        totalWritten += currentWritten;
+    }
+
     // qCDebug(KArchiveLog) << "wrote" << size << "bytes.";
-    const bool ok = written == size;
+    const bool ok = totalWritten == size;
 
     if (!ok) {
         setErrorString(tr("Error writing data: %1").arg(d->m_currentDev->errorString()));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.