19 UnZip unzip(std::move(zipFile));
23 bool gzipFile(
const QString &inFilename,
const QString &gzipFilename)
25 QFile infile(inFilename);
26 QFile outfile(gzipFilename);
28 if (!infile.open(QIODevice::ReadOnly))
30 LOG(VB_GENERAL, LOG_ERR, QString(
"gzipFile(): Error opening file for reading '%1'").arg(inFilename));
34 if (!outfile.open(QIODevice::WriteOnly))
36 LOG(VB_GENERAL, LOG_ERR, QString(
"gzipFile(): Error opening file for writing '%1'").arg(gzipFilename));
41 QByteArray uncompressedData = infile.readAll();
42 QByteArray compressedData =
gzipCompress(uncompressedData);
44 if (!outfile.write(compressedData))
46 LOG(VB_GENERAL, LOG_ERR, QString(
"gzipFile(): Error while writing to '%1'").arg(gzipFilename));
58 bool gunzipFile(
const QString &gzipFilename,
const QString &outFilename)
60 QFile infile(gzipFilename);
61 QFile outfile(outFilename);
63 if (!infile.open(QIODevice::ReadOnly))
65 LOG(VB_GENERAL, LOG_ERR, QString(
"gunzipFile(): Error opening file for reading '%1'").arg(gzipFilename));
69 if (!outfile.open(QIODevice::WriteOnly))
71 LOG(VB_GENERAL, LOG_ERR, QString(
"gunzipFile(): Error opening file for writing '%1'").arg(outFilename));
76 QByteArray compressedData = infile.readAll();
79 if (outfile.write(uncompressedData) < uncompressedData.size())
81 LOG(VB_GENERAL, LOG_ERR, QString(
"gunzipFile(): Error while writing to '%1'").arg(outFilename));
95 if (data.length() == 0)
98 std::array <char,1024> out {};
106 strm.avail_in = data.length();
107 strm.next_in = (Bytef*)(data.data());
109 int ret = deflateInit2(&strm,
110 Z_DEFAULT_COMPRESSION,
114 Z_DEFAULT_STRATEGY );
123 strm.avail_out = out.size();
124 strm.next_out = (Bytef*)(out.data());
126 ret = deflate(&strm, Z_FINISH);
128 Q_ASSERT(ret != Z_STREAM_ERROR);
135 (void)deflateEnd(&strm);
139 result.append(out.data(), out.size() - strm.avail_out);
141 while (strm.avail_out == 0);
152 if (data.length() == 0)
155 std::array<char,1024> out {};
164 strm.avail_in = data.length();
165 strm.next_in = (Bytef*)(data.data());
167 int ret = inflateInit2(&strm, 15 + 16);
176 strm.avail_out = out.size();
177 strm.next_out = (Bytef*)out.data();
178 ret = inflate(&strm, Z_NO_FLUSH);
180 Q_ASSERT(ret != Z_STREAM_ERROR);
187 (void) deflateEnd(&strm);
191 result.append(out.data(), out.size() - strm.avail_out);
193 while (strm.avail_out == 0);
195 (void) inflateEnd(& strm);