Thread: opening a zip file

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    12

    opening a zip file

    Hi all,

    I need code for opening a zip file (not extracting it) and reading the contents of the zip file.
    Pls help...

    Thanks in advance

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You can open it in binary mode, as you can do every file. You use b in fopen arguments, like wb, rb instead of r, w.
    Binary files are a sequence of 0 and 1. Text files are sequence of bytes that represent a character (usually an ASCII character).
    zip files are not different, you just need to know what you are doing (as always)

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Binary files are a sequence of 0 and 1. Text files are sequence of bytes
    There is no difference between binary and text files.

    Any file could be opened in the binary or text mode.
    In binary mode file is read as is.

    In text mode some conversions are done. Conversion depends on the OS.
    On windows, for example, 0x0D 0x0A sequence of bytes indicating the end-of line is replace with one character \n while reading, and back - when writing.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    12

    Question well the problem is ...

    guys i need 2 know how i can read the contents of a zip file without extracting it.

    well..now the picture's clear..aha

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by smooth View Post
    guys i need 2 know how i can read the contents of a zip file without extracting it.

    well..now the picture's clear..aha
    No, it is not clear.

    Do you need to fill buffer with the compressed contents of the zip-file?
    Do you want to extract the file list without extracting the files?
    Do you want to extract some file from the archive without extracting archive?
    Do you want to extract archive without using external programs?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    12
    sorry boss..lets make it clear now..

    want to extract the file list without extracting the files? (first)
    and then..
    want to read the files from the archive without extracting archive?

    pls reply

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by smooth
    want to extract the file list without extracting the files?
    This should be possible. I have little knowledge of the archive format, but the Wikipedia article claims that "the location of a file is indicated in the so called central directory which is located at the end of the ZIP file". As such, following the format specification you can get to that central directory and read it.

    Quote Originally Posted by smooth
    want to read the files from the archive without extracting archive?
    This sounds impossible by definition.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by smooth View Post
    sorry boss..lets make it clear now..

    want to extract the file list without extracting the files? (first)
    and then..
    want to read the files from the archive without extracting archive?

    pls reply
    Whilst Laserlight says it's impossible, I don't quite agree - you could decompress the content into memory without actually generating a file from it. However, on a scale 1..10, where 1 is simple and 10 is highly complex, I'd put this around 8.

    A much easier task would be to find a zip compatible library, and write some code to interface what you want into that archive.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by matsp
    Whilst Laserlight says it's impossible, I don't quite agree - you could decompress the content into memory without actually generating a file from it.
    I equated "extract" with "decompress".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM