opening a zip file

This is a discussion on opening a zip file within the C Programming forums, part of the General Programming Boards category; Hi all, I need code for opening a zip file (not extracting it) and reading the contents of the zip ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    21,636
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,636
    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".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21