Results 1 to 8 of 8

Thread: How To Extract A File

  1. #1
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How To Extract A File

    If I have all binary info about a file ( .jpg or .doc or any file ) in a .txt file how do I display
    it in that associated program without knowing which format is it .
    Say for example I have complete binary info including header and other meta info of test.pdf in binary format in a
    outdata.txt file. How do I display test.pdf after reading the outdata.txt.( in windows XP and with C /C ++ coding)
    Or say I have complete binary info including header and other meta info of image.jpg in binary format in a
    outdata.txt file. How do I display image.jpg after reading the outdata.txt.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How To Extract A File

    Can you elaborate on that? What do you mean by "complete binary info"? Do you also have the data file itself?

  3. #3
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Extract A File

    I shall attach an example
    The binary information of gun.jpg is in dk11.txt
    Now I want to show gun.jpg thru dk11.txt.
    I amnot aware that the info is of jpg file.Once you show dk11.txt (doubleclick on the dk11.txt) it will open in notepad/wordpad and you see all garbled info.
    This is where I want to have a small code which first checks what file type is there in binary form in this text file and opens it in the associated program in windows XP.
    Attached Images Attached Images
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How To Extract A File

    But this is still a jfif (commonly known as jpeg) file... The suffix of the file name doesn't change the type of the file. If you use a stupid operating system which relies on file extensions to guess file types then there is not much you can do. You'd have to implement your own mime-type recognition (often called mime-magic, as it "magically" guesses the file type by looking at the header) or use a library that does that. For example apache or cups (not sure about that though) use mime-magic to guess file types and they use a special file which contains signatures (simmilar to virus signatures) of file types. They then perform operations mentioned in the signature for each file type and stop when they find a match. In this particular example you could search for a "JFIF" string starting at byte 06h of the file. For PNG images you'd look for string "PNG" starting at byte 01h and a IHDR string shortly after (it's not neccessary to look for the IHDR string, but it'll make it more probable that you're facing a PNG file and not a plain text file starting with "xPNG".

    BTW. All files are "binary files" and contain "binary data" - even text files, so the term "binary data" doesn't really mean anything.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Extract A File

    AFAIR there's a library that can detect file type, but I don't remember it's name (I think I've seen it on Freshmeat).

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How To Extract A File

    $ ldd `which file`
    linux-gate.so.1 => (0xbfffe000)
    libmagic.so.1 => /usr/lib/libmagic.so.1 (0xb7f13000)
    libz.so.1 => /lib/libz.so.1 (0xb7f00000)
    libc.so.6 => /lib/i686/libc.so.6 (0xb7dd3000)
    /lib/ld-linux.so.2 (0xb7f3d000)
    I think this says it all

  7. #7
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Extract A File

    I need to use the code in windows based QT ( C ++)
    I am not sure how to use your code in that.Is it forlinux .
    Where will I write in the code, Presently I open the file with following code

    Qt Code:
    1. void steg::showdatafile()/*** THIS MODULE SHOWS THE DATA FILE *****/
    2. {
    3. if(QFile::exists(ui.datalineEdit->text()))
    4. {
    5. s << "url.dll,FileProtocolHandler" << ui.datalineEdit->text() ;
    6. p.startDetached(QString("rundll32.exe") , s );
    7. }
    8. else
    9. QMessageBox::warning(this, tr("FILE ERROR"),
    10. tr("<p><b> ERROR IN DISPLAYING DATA FILE.</b>"
    11. "</p><p><b>CHOOSE THE DATA FILE AND MAKE SURE THE FILE EXISTS OR CHOOSE SEPARATE FILE</b>"));
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    that is ----I am using FileProtocolHandler.But it is going to treat my file as text file where as my requirement is as told above.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How To Extract A File

    Well... Windows is the operating system I was talking about in one of my previous posts in this thread. If I were you, I'd check if libmagic compiles on your system. It's probably a GNU utility, so it will probably work.

    See here: http://gnuwin32.sourceforge.net/packages/file.htm

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 12:47
  2. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 20:24
  3. File permission QFile::WriteOther on Win Dos
    By patrik08 in forum Newbie
    Replies: 1
    Last Post: 13th June 2006, 15:16
  4. Accessing DTD in an XML file via QtXml module?
    By jorma in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2006, 19:09
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 15:52

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.