How do I load QBytesArray containing a zip file to QuaZip?

909 Views Asked by At

I'm using Qt Creator in a new project, so I don't know many things about this... :( I want to download a zip file, containing a json file, read this file and use that information. I can download the zip, save it in my disk and open it again to read json and use it. But I want to open my zip just in memory without really saving it... I have the zip info in a QByteArray and I need to send this "file" to QuaZip constructor/object. How do I do it?

1

There are 1 best solutions below

5
Konstantin T. On

You can use QBuffer. It provides a QIODevice interface for a QByteArray.

Example:

QByteArray byteArray("abc");
QBuffer buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
buffer.seek(3);
buffer.write("def", 3);
buffer.close();

Then you can use QuaZip::QuaZip(QIODevice *ioDevice) constructor to create QuaZip object.