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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:42:27+00:00 2026-06-10T04:42:27+00:00

All, I am just trying to get the zpipe demo working using dev-c++ where

  • 0

All,

I am just trying to get the zpipe demo working using dev-c++ where I have all the zlib code imported and using the zpipe.c as an example. Everything compiles and runs. If I try to create a gzip file using the commented out call to deflateInit2 it creates with now errors, but is corrupted when unzipping with 7zip. If I use the standard zlib headers to create the file, when I use the corresponding call to inflate it give me a return of -3/Z_DATA_ERROR indicating my defalte data is corrupted. Everything points to something being wrong in the def unction, but its pretty much exactly the example.

Any ideas?? Thanks so much in advance!

int main(int argc, char **argv)
{
     int ret;
     FILE *source;
     FILE *zip;
     FILE *zipped;
     FILE *back;

     source = fopen ("C:\\Users\\schmoudm\\Pictures\\caela.jpg", "r");
     zip = fopen ("C:\\Core\\RD\\test.gz", "w");

     printf ("calling def \n");
     ret = def(source, zip, Z_DEFAULT_COMPRESSION);
     printf("def return: %i \n", ret);
     fclose(source);
     fclose(zip);

     if (ret == 0) {
        printf ("setting up inf \n");
        zipped = fopen ("C:\\Core\\RD\\test.gz", "r"); 
        back = fopen ("C:\\Core\\RD\\zlibout.txt", "w"); 
        printf ("calling inf \n");
        ret = inf(zipped, back); 
        printf("inf return: %i \n", ret);  
        zerr(ret);
     }

    fclose(source);
    fclose(zip);

    printf("DONE!");
    system("PAUSE");
    return 0;
}

int def(FILE *source, FILE *dest, int level)
{
    int ret, flush;
    unsigned have;
    z_stream strm;
    unsigned char in[CHUNK];
    unsigned char out[CHUNK];

    /* allocate deflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;

    ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
    //ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8,       Z_DEFAULT_STRATEGY);
    if (ret != Z_OK)
        return ret;

    /* compress until end of file */
    do {
        strm.avail_in = fread(in, 1, CHUNK, source);
        printf("available in: %u \n", strm.avail_in);  
        if (ferror(source)) {
            (void)deflateEnd(&strm);
            return Z_ERRNO;
        }
        flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
        strm.next_in = in;

        /* run deflate() on input until output buffer not full, finish
           compression if all of source has been read in */
        do {
            strm.avail_out = CHUNK;
            strm.next_out = out;
            ret = deflate(&strm, flush);    /* no bad return value */
            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
            have = CHUNK - strm.avail_out;
            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
                (void)deflateEnd(&strm);
                return Z_ERRNO;
            }
        } while (strm.avail_out == 0);
        assert(strm.avail_in == 0);     /* all input will be used */

        /* done when last data in file processed */
    } while (flush != Z_FINISH);
    assert(ret == Z_STREAM_END);        /* stream will be complete */

    /* clean up and return */
    (void)deflateEnd(&strm);
    return Z_OK;
}
  • 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-10T04:42:29+00:00Added an answer on June 10, 2026 at 4:42 am

    but its pretty much exactly the example.

    Alas, you left out a critical portion from zpipe.c.

    #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
    #  include <fcntl.h>
    #  include <io.h>
    #  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
    #else
    #  define SET_BINARY_MODE(file)
    #endif
    

    and

    /* avoid end-of-line conversions */
    SET_BINARY_MODE(stdin);
    SET_BINARY_MODE(stdout);
    

    So in your code you need to do SET_BINARY_MODE(source) and SET_BINARY_MODE(zip).

    Or you need to use the "b" option in both fopen()‘s.

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

Sidebar

Related Questions

I'm just trying to get admob running and tested different working code examples from
Please excuse poor code atm, just trying to get it working before making it
Newbie: I am just trying to get the example code shown below to work.
I can't get spring annotations to work at all, I'm just trying to get
I'm using PHP. I'm trying to get a Regex pattern to match everything between
Just trying to get the (.portfoliocategs) category menu on this site to have a
So I'm trying to get some basic jQuery code with Rails working, but it
I have a little sample application I was working on trying to get some
just trying to get my head around Rx I am using Rx to poll
I'm just trying to get a list of all the folders that resides on

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.