Results 1 to 4 of 4

Thread: Better usage of a downloaded binary

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Better usage of a downloaded binary

    Hello!

    In my application I need to download a binary file from a server and use its contents. I was already able to download it and save it into a binary file, so it seems that the downloaded part is OK.

    The problem is that I don't know what is the best option: to download the file in a .bin and open it with Qt and read it, or to save the data into a internal buffer and to use this buffer. Interesting to notice is that I don't need the file in my PC.

    In case I donwload and save it in a buffer inside my software, which data "container" is the best to storage the bin data? QByteArray? And which functions and classes should I use to read this data and work with it given the fact is binary?


    Thanks!

    Momergil

  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: Better usage of a downloaded binary

    If you don't need to actually store the file on disk after retrieving it from the server, then keeping it in memory is just fine as long as you are always guaranteed that there will be enough memory available to keep the entire file. What happens if you run out of memory halfway through the download? I personally think it is far better to break a process like this into independent, reliable parts: first download the file and save it (to a temporary file if you want), then open the file and read it into memory. In this case, if the file is too big to completely read into memory, then at least you haven't lost the entire thing and your application can take an alternative path and use it in pieces if possible.

    As far as what do do with it after you have read it in, this is like asking "How long is a piece of string?".

    It depends entirely on what is inside the file. Is it an EXE, is it an MP3, is it a video? If the file has structured data inside it, then you would want to map that data onto C++ objects that put the binary data into appropriate member variables. Since you haven't told us anything about the files except that they are binary, we can only guess at how you might want to use one. QByteArray is probably fine for holding the raw bytes of the file, but in order to do anything with it, you'll have to map the binary bytes in QByteArray into something meaningful.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Better usage of a downloaded binary

    Also take a look at QBuffer.

  4. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Better usage of a downloaded binary

    Thanks for the tips! That certanly will help.



    Momergil

Similar Threads

  1. Replies: 1
    Last Post: 8th December 2011, 08:04
  2. Trojan in Qt 4.7.1 Windows Installer (Non Creator) downloaded from Qt Website
    By Gavin Harper in forum Installation and Deployment
    Replies: 2
    Last Post: 17th November 2010, 21:54
  3. QML usage
    By icek in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2010, 17:02
  4. Replies: 11
    Last Post: 20th March 2007, 09:51
  5. Qt4 XML usage
    By kandalf in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2006, 20:18

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.