zgulser
12th October 2012, 18:14
Hi,
After I zip my data using the code below, I can create the zip file and it's size is quite logical. But when I attempt to unzip it using WinZip, Winzip gives me an error.
I'm working on Microsoft VS 2O1O and using Qt 4.8.
Any ideas?
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 = "";
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("", "")))
{
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return NULL;
}
//while(inFile.getChar(&c)&&outFile.putChar(c));
for(int i=0; i < p_BytesToBrCompressed.size(); i++)
{
outFile.putChar(p_BytesToBrCompressed.at(i));
}
if(outFile.getZipError()!=UNZ_OK)
{
qDebug() << "AQQQQQQQQQQQQQQQQ!!";
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return NULL;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return NULL;
}
QFile reader(p_name);
if(QFile::exists(p_name))
{
if(reader.open(QIODevice::ReadOnly))
{
compressedData.append(reader.readAll());
}
}
inFile.close();
zip.close();
if(zip.getZipError()!=0)
{
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return NULL;
}
qDebug() << "Compressed Data: " << compressedData;
return compressedData;
}
Added after 1 24 minutes:
Hi again,
The problem was in;
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("", "")))
so replacing the above line with;
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("syd_barrett.txt")))
solved the problem.
Unfortunately in Quazip, there is nothing to alert the user for this case at least.
Anyway, the problem solved and thanks.
After I zip my data using the code below, I can create the zip file and it's size is quite logical. But when I attempt to unzip it using WinZip, Winzip gives me an error.
I'm working on Microsoft VS 2O1O and using Qt 4.8.
Any ideas?
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 = "";
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("", "")))
{
qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
return NULL;
}
//while(inFile.getChar(&c)&&outFile.putChar(c));
for(int i=0; i < p_BytesToBrCompressed.size(); i++)
{
outFile.putChar(p_BytesToBrCompressed.at(i));
}
if(outFile.getZipError()!=UNZ_OK)
{
qDebug() << "AQQQQQQQQQQQQQQQQ!!";
qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
return NULL;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
return NULL;
}
QFile reader(p_name);
if(QFile::exists(p_name))
{
if(reader.open(QIODevice::ReadOnly))
{
compressedData.append(reader.readAll());
}
}
inFile.close();
zip.close();
if(zip.getZipError()!=0)
{
qWarning("testCreate(): zip.close(): %d", zip.getZipError());
return NULL;
}
qDebug() << "Compressed Data: " << compressedData;
return compressedData;
}
Added after 1 24 minutes:
Hi again,
The problem was in;
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("", "")))
so replacing the above line with;
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo("syd_barrett.txt")))
solved the problem.
Unfortunately in Quazip, there is nothing to alert the user for this case at least.
Anyway, the problem solved and thanks.