zgulser
28th June 2012, 13:56
Hi,
I'm using QuaZip to archive my files like the following;
QByteArray LoggerManager::packFiles(const QString& p_name, const QByteArray& p_BytesToBrCompressed)
{
QString testZip = p_name;
QuaZip zip(testZip);
zip.setFileNameCodec("IBM866"); /* or Windows-1250 */
if(!zip.open(QuaZip::mdCreate))
{
qWarning("testCreate(): zip.open(): %d", zip.getZipError());
return NULL;
}
QString loc = qApp->applicationDirPath() + "/logs/error_log/";
QFileInfoList files=QDir(loc).entryInfoList();
QFile inFile;
QFile inFileTmp;
QuaZipFile outFile(&zip);
char c;
QByteArray compressedData = "";
foreach(QFileInfo file, files)
{
if(!file.isFile())
continue;
inFileTmp.setFileName(file.fileName());
inFile.setFileName(file.filePath());
if(!inFile.open(QIODevice::ReadOnly))
{
qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
return NULL;
}
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(inFileTmp.fileName(), inFile.fileName())))
{
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return NULL;
}
while(inFile.getChar(&c)&&outFile.putChar(c));
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return NULL;
}
compressedData = outFile.readAll();
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return NULL;
}
inFile.close();
}
zip.close();
if(zip.getZipError()!=0)
{
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return NULL;
}
return compressedData;
}
The problem is; I want to send this zipped content to an HTTP server. But
compressedData = outFile.readAll();
is non-sense since outFile is writeOnly which makes compressedData empty string.
I try the following to overcome this situation;
QFile reader(p_name);
if(QFile::exists(reader.fileName()))
{
if(reader.open(QIODevice::ReadOnly))
{
compressedData.append(reader.readAll());
}
}
But it didn't work either..
Any ideas?
I'm using QuaZip to archive my files like the following;
QByteArray LoggerManager::packFiles(const QString& p_name, const QByteArray& p_BytesToBrCompressed)
{
QString testZip = p_name;
QuaZip zip(testZip);
zip.setFileNameCodec("IBM866"); /* or Windows-1250 */
if(!zip.open(QuaZip::mdCreate))
{
qWarning("testCreate(): zip.open(): %d", zip.getZipError());
return NULL;
}
QString loc = qApp->applicationDirPath() + "/logs/error_log/";
QFileInfoList files=QDir(loc).entryInfoList();
QFile inFile;
QFile inFileTmp;
QuaZipFile outFile(&zip);
char c;
QByteArray compressedData = "";
foreach(QFileInfo file, files)
{
if(!file.isFile())
continue;
inFileTmp.setFileName(file.fileName());
inFile.setFileName(file.filePath());
if(!inFile.open(QIODevice::ReadOnly))
{
qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
return NULL;
}
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(inFileTmp.fileName(), inFile.fileName())))
{
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return NULL;
}
while(inFile.getChar(&c)&&outFile.putChar(c));
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return NULL;
}
compressedData = outFile.readAll();
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return NULL;
}
inFile.close();
}
zip.close();
if(zip.getZipError()!=0)
{
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return NULL;
}
return compressedData;
}
The problem is; I want to send this zipped content to an HTTP server. But
compressedData = outFile.readAll();
is non-sense since outFile is writeOnly which makes compressedData empty string.
I try the following to overcome this situation;
QFile reader(p_name);
if(QFile::exists(reader.fileName()))
{
if(reader.open(QIODevice::ReadOnly))
{
compressedData.append(reader.readAll());
}
}
But it didn't work either..
Any ideas?