PDA

View Full Version : Archive multiple files in one (without compression, just store)



xcxl
21st May 2020, 14:52
Hi everyone,

I would like to pack all my 6 "save files" of my application in only one file "save.data" (like a zip, but with no compression at all). These days, when I send a save file to a user, it's a directory with files in it, and it's not so convenient for the user.
Is someone has a short source code to do that? I suppose it's something like writing all in binary in one file, and adding the header at the end with each start byte, but I would be much easier for me if someone has done it before with a QByteArray or anything else.

Thank you!

d_stranz
21st May 2020, 18:13
It's pretty hard to believe that you have users who don't know how to unzip a zip file. If they can't do that simple task, how are they going to use a program that you write for them that does basically the same thing (and wastes space and transmission overhead because it isn't compressed)?

In any case, the programs are dead simple to write.

To create the file, read each of your files into a QByteArray, then write each QByteArray out to the output file using a QDataStream. Write the name of the file first, then the QByteArray, then the name of the next file and its array, and so on. The QDataStream operators for each class (QString and QByteArray) will write whatever additional information is needed to allow re-creating themselves when the data is unpacked.

To unpack the file, open it, read the QString containing the file name, create the output file, read the QByteArry, then use a second QDataStream to write it out to the new file. Repeat until you reach the end of the input file.

xcxl
22nd May 2020, 07:42
It's pretty hard to believe that you have users who don't know how to unzip a zip file.
Sorry I wasn't very clear with the goal ; I don't want the user to have the 6 save file, I want the user to have always one single save file they load with the software, and not the "confUI.dat", "confUser.data", "initParameter.data", etc... that's why I would like to put all these data file in one for the user.


To create the file, read each of your files into a QByteArray, then write each QByteArray out to the output file using a QDataStream. Write the name of the file first, then the QByteArray, then the name of the next file and its array, and so on. The QDataStream operators for each class (QString and QByteArray) will write whatever additional information is needed to allow re-creating themselves when the data is unpacked.

To unpack the file, open it, read the QString containing the file name, create the output file, read the QByteArry, then use a second QDataStream to write it out to the new file. Repeat until you reach the end of the input file.
Great, thank you d_stranz, I now have a solution easy to implement :)

Have a good day

Lesiok
22nd May 2020, 08:38
Inferring from file names they are sets of parameters. Maybe QSettings nad INI format will be the solution. File name will be group name.