Results 1 to 4 of 4

Thread: Archive multiple files in one (without compression, just store)

  1. #1
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Archive multiple files in one (without compression, just store)

    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!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Archive multiple files in one (without compression, just store)

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    xcxl (22nd May 2020)

  4. #3
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Archive multiple files in one (without compression, just store)

    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

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Archive multiple files in one (without compression, just store)

    Inferring from file names they are sets of parameters. Maybe QSettings nad INI format will be the solution. File name will be group name.

Similar Threads

  1. read and store ini files sections
    By vijay kumar in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2014, 12:52
  2. Best place to store some textual files
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2013, 19:49
  3. Replies: 0
    Last Post: 13th December 2012, 07:35
  4. store and read mp3 files from buffer
    By vinayaka in forum Newbie
    Replies: 2
    Last Post: 2nd August 2011, 11:25
  5. Replies: 12
    Last Post: 17th June 2009, 06:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.