Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compressing Data in VC

Posted on 2004-10-28
10
Medium Priority
?
388 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
Comment
Question by:Gene Klamerus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 672 total points
ID: 12437127
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
ID: 12437410
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:Gene Klamerus
ID: 12440123
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Assisted Solution

by:jacobhoover
jacobhoover earned 664 total points
ID: 12440182
Hmm,
  you could also look at:
http://www.codeproject.com/cpp/zip.asp.
0
 
LVL 3

Expert Comment

by:georg74
ID: 12444115
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:Gene Klamerus
ID: 12449441
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
georg74 earned 664 total points
ID: 12449757
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
ID: 12449775
PS: did you know Solaris 10, the OS of Sun is going open source?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

618 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