CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Dec 2001
    Posts
    391

    Question Help with ZLIB. What am I doing wrong??

    I just cant get the following code to work. First off the ZLIB compressor isnt compressing/uncompressing correctly (the src is originally 680kb, compressed = 78kb, uncompressed = 80kb) and many times over the statement: inp.open("d:\\Test20.zip", ios::binary); in the "uncompress area" isnt able to open the file for some reason setting "inp" to 0. What am i doing wrong within the following code?

    The zlib header, libz.lib, and zlib.dll are available.

    ---
    // ZLIB.cpp : Defines the entry point for the console application.

    #include "stdafx.h"
    #include "zlib.h"
    #include <fstream>

    using namespace std;

    int main(int argc, char *argv[])
    {
    char *des, *src;
    unsigned long desLen, tdesLen, srcLen, rlen;
    std::ifstream inp;
    std::ofstream oup;

    /////////////////////////////////////////
    // Compress Test20.exe to Test20.zip
    /////////////////////////////////////////
    inp.open("d:\\Test20.exe", ios::binary);
    oup.open("d:\\Test20.zip", ios::binary);

    srcLen=3000;
    desLen=tdesLen=srcLen*1.001+12;

    src=new char[srcLen];
    des=new char[desLen];

    inp.read(src,srcLen);
    rlen=inp.gcount();

    while(rlen)
    {
    compress2((Bytef *) des,&tdesLen,(Bytef *)src,rlen,2);
    oup.write(des,tdesLen);
    tdesLen=desLen;
    inp.read(src,srcLen);
    rlen=inp.gcount();
    }

    oup.close();
    inp.close();


    /////////////////////////////////////////
    // Uncompress Test20.zip to Test20B.exe
    /////////////////////////////////////////
    inp.open("d:\\Test20.zip", ios::binary);
    oup.open("d:\\Test20B.exe", ios::binary);

    srcLen=3000;
    desLen=tdesLen=srcLen*1.001+12;

    inp.read(src,srcLen);
    rlen=inp.gcount();

    while(rlen)
    {
    uncompress((Bytef *) des,&tdesLen,(Bytef *)src,rlen);
    oup.write(des,tdesLen);
    tdesLen=desLen;
    inp.read(src,srcLen);
    rlen=inp.gcount();
    }

    oup.close();
    inp.close();


    return 0;
    }

    ---
    Last edited by quantass; January 28th, 2003 at 04:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured