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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:37:40+00:00 2026-05-28T03:37:40+00:00

I have a gzip file that is in memory, and I would like to

  • 0

I have a gzip file that is in memory, and I would like to uncompress it using zlib, version 1.1.3. Uncompress() is returning -3, Z_DATA_ERROR, indicating the source data is corrupt.

I know that my in memory buffer is correct – if I write the buffer out to a file, it is the same as my source gzip file.

The gzip file format indicates that there is a 10 byte header, optional headers, the data, and a footer. Is it possible to determine where the data starts, and strip that portion out? I performed a search on this topic, and a couple people have suggested using inflateInit2(). However, in my version of zlib, that function is oddly commented out. Is there any other options?

  • 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-28T03:37:41+00:00Added an answer on May 28, 2026 at 3:37 am

    Is it possible to determine where the data starts, and strip that portion out?

    Gzip has the following magic number:

    static const unsigned char gzipMagicBytes[] = { 0x1f, 0x8b, 0x08, 0x00 };
    

    You can read through a file stream and look for these bytes:

    static const int testElemSize = sizeof(unsigned char);
    static const int testElemCount = sizeof(gzipMagicBytes);
    
    const char *fn = "foo.bar";
    FILE *fp = fopen(fn, "rbR");
    char testMagicBuffer[testElemCount] = {0};
    unsigned long long testMagicOffset = 0ULL;
    
    if (fp != NULL) {
        do {
            if (memcmp(testMagicBuffer, gzipMagicBytes, sizeof(gzipMagicBytes)) == 0) {
                /* we found gzip magic bytes, do stuff here... */
                fprintf(stdout, "gzip stream found at byte offset: %llu\n", testMagicOffset);
                break;
            }
            testMagicOffset += testElemSize * testElemCount;
            fseek(fp, testMagicOffset - testElemCount + 1, SEEK_SET);
            testMagicOffset -= testElemCount + 1;
        } while (fread(testMagicBuffer, testElemSize, testElemCount, fp));
    }
    
    fclose(fp);
    

    Once you have the offset, you could do copy and paste operations, or overwrite other bytes, etc.

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

Sidebar

Related Questions

I have some data that I would like to gzip, uuencode and then print
I have a text file that is 310MB in size (uncompressed). When using PerlIO::gzip
I have a web service that serves a javascript source file to browsers. The
I have a gzip file and currently I read it like this: infile =
I have an html file saved in gzip format. The browser displays the html
Assume I have a regular fixed width file that is sorted on one of
So I have a script that does attempts to create a sql file on
I have method to compress file with GZip: public static void CompressFile(string filePath) {
I have a very large file (~10 GB) that can be compressed to <
I have a File Transfer Application that sends files and folders. (Server - client)

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.