PDA

View Full Version : A problem regarding QuaZip



zgulser
28th June 2012, 14: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?

high_flyer
28th June 2012, 15:26
Does the server support only HTTP? FTP would be better.

Is the archive read-only file (in the file system) or do you mean its only the attribute with which you open the QFile object, but the file it self is not read-only?

But it didn't work either..

By "not working" do you mean compressData is empty?

zgulser
28th June 2012, 15:31
Does the server support only HTTP? FTP would be better.


Yepp!



Is the archive read-only file (in the file system) or do you mean its only the attribute with which you open the QFile object, but the file it self is not read-only?


arcihive is opened write-only by default. That's why I can't read it. And I opened QFile object ad read-only by myself.



By "not working" do you mean compressData is empty?


Sorry..Yes.

high_flyer
28th June 2012, 15:39
and you are sure (by means of stepping trough or debug message) that:
compressedData.append(reader.readAll());
is being called?

zgulser
28th June 2012, 15:43
Yeah, definitely...

high_flyer
28th June 2012, 15:54
What is the size of the file when you look it up with a file manager?
What is the size of the file when you do reader.size()?

zgulser
28th June 2012, 16:34
it's size seems completely logical to me. About 20000 bytes.

wysota
28th June 2012, 17:12
And you can't reopen it in read only mode after you're done creating the archive?

zgulser
28th June 2012, 17:40
Hi,

I'm very sorry to take your time but my problem caused by VS 2010 debugger. I was actually reading the file contents properly but the debugger doesn't show me. When I did qDebug, I saw all the contents of the file that i'm reading.

thanks for your care.