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 6325417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:53:35+00:00 2026-05-24T16:53:35+00:00

I have a ZipFile and I’d like to create an array with the offsets/sizes

  • 0

I have a ZipFile and I’d like to create an array with the offsets/sizes of each entry in it. This is so that a C++ layer (JNI) can read these subfiles directly without having to extract them.

I can get the file’s compressed size using entry.getCompressedSize() but I don’t see anything to find out the offset of the file within the zip.

Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while (zipEntries.hasMoreElements())
{
    ZipEntry zip = (ZipEntry)zipEntries.nextElement();
    //long offset = ?
    long fileSize = zip.getCompressedSize();
}

Any easy way to get this?

  • 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-05-24T16:53:36+00:00Added an answer on May 24, 2026 at 4:53 pm

    I read that entries are returned by .entries() in the exact order they occur in the file (unsure if this refers to the actual file or the header entry.) Assuming this to be the case the following solves the problem:

    Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
    long offset = 0;
    while (zipEntries.hasMoreElements())
    {
        ZipEntry entry = (ZipEntry)zipEntries.nextElement();
        long fileSize = 0;
        long extra = entry.getExtra() == null ? 0 : entry.getExtra().length;
        offset += 30 + entry.getName().length() + extra;
        if(!entry.isDirectory())
        {
            fileSize = entry.getCompressedSize();
    
            // Do stuff here with fileSize & offset
        }    
        offset += fileSize;
    }
    

    This is working for my case. The only thing to note though is that according to the ZIP compression spec, it’s not a given that in all zip files the files be stored in exactly the same order as in the directory. Since in my case I have control of the construction of the zip file this isn’t a problem but this approach may not work if you work with zips from an uncontrolled source.

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

Sidebar

Related Questions

I have an app with two packages.. My setup.py is like this: sys.argv.append('py2exe') setup(
I have a big zipfile that I need to split in multiple zip files.
I have a script that checks a zipfile containing a number of matching PDF+textfiles.
I have this code: # File: zipfile-example-1.py import zipfile,os,glob file = zipfile.ZipFile(Apap.zip, w) #
Let's say that I have a website where I'd like users to be able
Hi have create from window 7 and put that in server.Now i am downloading
So here's my problem. I have a python script that takes a zipfile and
I have a zip file containing a folder structure like main-folder/ subFolder1/ subFolder2/ subFolder3/
I have always wondered about this. So many application setups have a zip file
I have found that creating a zip file using the Zip task provided by

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.