Solved

Compressing Data in VC

Posted on 2004-10-28
364 Views
Last Modified: 2013-11-13
We have an application we run on Windows NT and Windows 2000 servers (we are finally just upgrading to 2000).  This application has a number of components, but we have a question that is related to 2 of them that handle printing specifically.

The first of these components creates PS files from PS data it finds in an MQ Series queue.  It saves to a UNC, although the \\server\share\file.ps is currently local to the server upon which the component is running.

The second program copies those to a printer via that printer's UNC (which is part of the filename).  These printers are across the network.

These PS files can often be relatively big (1-2 MB) because they have embedded Asian language fonts.  At the same time, the reason they have these fonts is that they are destined for printers in Asian countries.  The networking to these countries is pretty poor and it can take 5-10 minutes to send the file to the remote printer.  That's a problem when we're sending thousands of files in a day.

We can't reduce the content of the PS file, but we think we could compress the file as we send it across the network.  The files compress to about 1/3 of their original size when we zip them.

We are thinking of having the first program saves to a remote UNC, and running the second program on those remote servers (the servers being in the same office as the printers).  We might even be able to do this with a workstation.

These components were written in Visual C/C++.  We originally wrote them in VS v6.0, but we're now working with it within the Visual Studio .Net framework (but it's not managed code or anything).  These two components run as Windows services (they have the necessary service code in them).

We're rather not purchase a vendor DLL if we don't need to and we would like to know if there is a Windows API for compressing/decompressing data or files already available that we could test and use?
0
Question by:klamerus
    8 Comments
     
    LVL 48

    Accepted Solution

    by:
    The code for zipping files is in the public domain - gzip and gunzip come with source and are distributed under the GNU license agreement. You could look at the code and see if you can work it into your code.

    Alternatively you could use an already compiled version of gzip to compress the data and simply shell (ShellExecute or CreateProcess) the application to compress the file. This would save you a lot of time of integrating the code into your existing app and you would have the benefit of a tried and tested solution and you could always swap it out for something better at a later stage if something came along.

    0
     
    LVL 3

    Expert Comment

    by:georg74
    I agree with julianH second tip. Create the postscript file locally. Then call the external utility to compress it,
    then copy it to the remote computer. There, you can uncompress it directly to the print spooler.

    There are several (command-line) compression utilities, many of them are free to use even for commercial applications:
    gzip, zip, winzip command line interface, arj, rar, lha, ...
    You may first want to test which of them compresses your files best and fast.

    If this is an issue, use .zip files so even windows-only people will know what they are an how to unpack them.

    gl,
    georg

    PS: winXP has "built-in" zipping, but it is a dll and the user interface is crap, and so there is no convenient way to call it
    out of an application or command line.
    0
     
    LVL 1

    Author Comment

    by:klamerus
    our experience is that shelling to command-line is fairly error prone and provides very poor diagnostics information upon failure.  We have the data we need to compress in memory (from MQ), so we want to compress that string and do the write to the UNC.  If that doesn't work, we'll fail back to something lesser.

    I would have expected Windows 2000 and XP to have some sort of compression API, at the very least to support the compression it does itself.

    We could use Dynazip (it's not too expensive), but just thought there would be something around.
    0
     
    LVL 7

    Assisted Solution

    by:jacobhoover
    Hmm,
      you could also look at:
    http://www.codeproject.com/cpp/zip.asp.
    0
     
    LVL 3

    Expert Comment

    by:georg74
    there is a numer algorithms and different implementations available, as source code or library, but the concept of combining different (small) utilities or modules togeather (like piping the data to the next process) is much safer than trying to incorporate everything into a single application. So if an improvement or bug correction is dont to a part of it (like file compression), you just exchange it without having to recompile and eventually change other parts.

    shelling to command line is more error prone only if you don't check the resulting error code.

    one important questio is how do you want to decompress the file.

    hth,
    g.
    0
     
    LVL 1

    Author Comment

    by:klamerus
    We have 2 programs, one that writes the data to a file and another that reads the file and prints it.  We want the first to compress and the second to decompress, in memory.

    Command-line is more error prone regardless of checking.  The options of available exit codes is gernally poorer for command-line utilities.

    So far as combining modules, we're talking about a program that is 1-2000 lines of size, which is hardly monolithic.  Our application is already comprized of 12 interoperating components (sharing information via MQ queues).

    We also don't want open source.  We want something commercially supported.  We find that works best for support.
    0
     
    LVL 3

    Assisted Solution

    by:georg74
    klamerus,

    zlib is the widest used and therfore tested compression library.

    open source does not mean no support.
    you can yery well get commercial support for open source software.
    if you want an offer - ask for it. my company can provide it.
    i also know few other reliable companies which commercialy
    support open source code, so it won't be hard to find one.

    technical details:
    for in-memory compressing, you get two functions:

    int compress (Bytef *dest,   uLongf *destLen, const Bytef *source, uLong sourceLen);

         Compresses the source buffer into the destination buffer.  sourceLen is
       the byte length of the source buffer. Upon entry, destLen is the total
       size of the destination buffer, which must be at least 0.1% larger than
       sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
       compressed buffer.
         This function can be used to compress a whole file at once if the
       input file is mmap'ed.
         compress returns Z_OK if success, Z_MEM_ERROR if there was not
       enough memory, Z_BUF_ERROR if there was not enough room in the output
       buffer.

    int  compress2 (Bytef *dest,   uLongf *destLen, const Bytef *source, uLong sourceLen, int level);

         Compresses the source buffer into the destination buffer. The level
       parameter has the same meaning as in deflateInit.  sourceLen is the byte
       length of the source buffer. Upon entry, destLen is the total size of the
       destination buffer, which must be at least 0.1% larger than sourceLen plus
       12 bytes. Upon exit, destLen is the actual size of the compressed buffer.

         compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
       memory, Z_BUF_ERROR if there was not enough room in the output buffer,
       Z_STREAM_ERROR if the level parameter is invalid.


    int uncompress (Bytef *dest,   uLongf *destLen, const Bytef *source, uLong sourceLen);

         Decompresses the source buffer into the destination buffer.  sourceLen is
       the byte length of the source buffer. Upon entry, destLen is the total
       size of the destination buffer, which must be large enough to hold the
       entire uncompressed data. (The size of the uncompressed data must have
       been saved previously by the compressor and transmitted to the decompressor
       by some mechanism outside the scope of this compression library.)
       Upon exit, destLen is the actual size of the compressed buffer.
         This function can be used to decompress a whole file at once if the
       input file is mmap'ed.

         uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
       enough memory, Z_BUF_ERROR if there was not enough room in the output
       buffer, or Z_DATA_ERROR if the input data was corrupted.

    the data format user is standardized in RFCs 1950 - 1952

    HTH,
    georg
    0
     
    LVL 3

    Expert Comment

    by:georg74
    PS: did you know Solaris 10, the OS of Sun is going open source?
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    sumDigits challenge 9 54
    factorial example challenge 10 34
    powerN  challenge 3 20
    strCount chalenge 3 19
    This article will show, step by step, how to integrate R code into a R Sweave document
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now