Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:23:07+00:00 2026-06-12T04:23:07+00:00

I am using a library called objective zip to extract a file. the relevant

  • 0

I am using a library called objective zip to extract a file.

the relevant code:

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];


ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:requestFinishedPresentationPath mode:ZipFileModeUnzip];
NSArray *infos= [unzipFile listFileInZipInfos];


for (FileInZipInfo *info in infos) {
    NSLog(@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level);

    [unzipFile locateFileInZip:info.name];

    // Expand the file in memory
    ZipReadStream *read= [unzipFile readCurrentFileInZip];

    NSMutableData *data = [[NSMutableData alloc] initWithLength:256];
    int bytesRead = [read readDataWithBuffer:data];



    [data writeToFile:[documentsDir stringByAppendingPathComponent:info.name] atomically:NO];
    NSLog([documentsDir stringByAppendingPathComponent:info.name]);
    [read finishedReading];


}

[unzipFile close];

the first nslog outputs the following:

- _some-path_/modules/reference-popup/ref-popup.js 2012-08-21 08:49:36 +0000 109 (-1)

the second nslog outputs the follows:

/Users/_USER_/Library/Application Support/iPhone Simulator/5.1/Applications/F2649DB7-7806-4C49-8DF9-BD939B2A9D5A/Documents/_some-path_/modules/slide-popup/slide-popup.css

Basically i think my read and data objects are not talking to each other… when I navigate to the right directory in my browser, all it does is show the two files, which are supposed to be directories (they are the most top-level directories) but the browser says they were written out as 1kb files. I try and view the file and its a 256 byte file… as per the buffer in the code.

What should I do instead?

To expand a zip (with all the files into a directory properly)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:23:08+00:00Added an answer on June 12, 2026 at 4:23 am

    Calling readDataWithBuffer will fill up the buffer (up to its length) and then pause the stream. You should actually put it in a loop and stop when bytesRead is 0. This is to allow expanding files bigger than available memory (think of a video, for example).

    Also, consider that zip files have no directory structure: directories are simply embedded as part of the zipped file names. It’s up to you to recreate the correct path. Usually you have some base directory, append the zipped file name and create the file with the resulting complete path.

    In the Objective-Zip wiki, at the end, you can find a section titled Memory Management where a sample loop is present and commented. A more completed example is the following:

        // Open zip descriptor
        ZipFile *zip= [[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeUnzip];
    
        NSMutableData *buffer= [[NSMutableData alloc] initWithLength:BUFFER_SIZE];
    
        // Loop on file list
        NSArray *zipContentList= [zip listFileInZipInfos];
        for (FileInZipInfo *fileInZipInfo in zipContentList) {
    
            // Check if it's a directory
            if ([fileInZipInfo.name hasSuffix:@"/"]) {
                NSString *dirPath= [documentsPath stringByAppendingPathComponent:fileInZipInfo.name];
                [[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:NULL];
                continue;
            }
    
            // Create file
            NSString *filePath= [documentsPath stringByAppendingPathComponent:fileInZipInfo.name];
            [[NSFileManager defaultManager] createFileAtPath:filePath contents:[NSData data] attributes:nil];
            NSFileHandle *file= [NSFileHandle fileHandleForWritingAtPath:filePath];
    
            // Seek file in zip 
            [zip locateFileInZip:fileInZipInfo.name];
            ZipReadStream *readStream= [zip readCurrentFileInZip];
    
            // Reset buffer
            [buffer setLength:BUFFER_SIZE];
    
            // Loop on read stream
            int totalBytesRead= 0;
            do {
                int bytesRead= [readStream readDataWithBuffer:buffer];
                if (bytesRead > 0) {
    
                    // Write data
                    [buffer setLength:bytesRead];
                    [file writeData:buffer];
    
                    totalBytesRead += bytesRead;
    
                } else
                    break;
    
            } while (YES);
    
            // Close file
            [file closeFile];
            [readStream finishedReading];
        }
    
        // Close zip and release buffer
        [buffer release];
        [zip close];
        [zip release];
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a library called EXIFextractor to extract metadata information from images. This
I have a compiled external library that I'm using in my (Objective-C++) code. This
I am using a library called mxGraph and in my code I subscribe for
I'm using a PHP library called solr-php-client (http://code.google.com/p/solr-php-client/) to interface with my Solr server.
I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In
I'm using a javascript library called d3 in order to perform some animations on
I am using an open source java library called Weka in an Eclipse Indigo
Given an app called ExampleApp, I want to find ~/Library/Logs/ExampleApp basically without using hard
Im using opensource library called wxFreeChart to draw some XY charts. In example there
I am using a library called libmosquitto in an iPhone app. The library is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.