473,378 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Incremental Compression

Hey.

I have a problem in some network code. I want to send my packets compressed,
but I don't want to compress each packet separately (via .encode('zlib') or
such) but rather I'd like to compress it with regard to the history of the
compression stream. If I use zlib.compressobj and flush it to get the
packet data, I cannot continue to compress with that stream.

I cannot wait until the end of the stream and then flush, because I need to
flush after every packet.

Another capability I require is to be able to copy the compression stream.
i.e: To be able to create multiple continuations of the same compression
stream. Something like:

a = compressobj()
pre_x = a.copy()
x = a.compress('my_packet1')
# send x
# x was not acked yet, so we must send another packet via the pre_x
compressor
y = pre_x.compress('my_packet2')

Is there a compression object that can do all this?
Mar 25 '06 #1
2 2230
On Sat, 2006-03-25 at 03:08 +0200, Eyal Lotem wrote:
Hey.

I have a problem in some network code. I want to send my packets compressed,
but I don't want to compress each packet separately (via .encode('zlib') or
such) but rather I'd like to compress it with regard to the history of the
compression stream. If I use zlib.compressobj and flush it to get the
packet data, I cannot continue to compress with that stream.
Yes, you can.

Help on built-in function flush:

flush(...)
flush( [mode] ) -- Return a string containing any remaining
compressed data.
mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH,
Z_FINISH; the
default value used when mode is not specified is Z_FINISH.
If mode == Z_FINISH, the compressor object can no longer be used
after
calling the flush() method. Otherwise, more data can still be
compressed.

you want to call

mycompressor.flush( zlib.Z_SYNC_FLUSH )

The difference between the flushes is this:

1. Z_SYNC_FLUSH. This basically send enough data so that the receiver
will get everything you put in. This does decerase your compression
ratio (however, in weird case when I last played with it, it helped.)

2. Z_FULL_FLUSH. This sends enough data so that the receiver will get
everything you put in. This also wipes the compressors statistics, so
the when you pick up where you left of, the compressor will compress
about as well as if you had just started, you are wiping its memory of
what it saw in the past.

3. Z_FINISH. This is the default action, this is what is killing you.

Good luck - Adam DePrince

I cannot wait until the end of the stream and then flush, because I need to
flush after every packet.

Another capability I require is to be able to copy the compression stream.
i.e: To be able to create multiple continuations of the same compression
stream. Something like:

a = compressobj()
pre_x = a.copy()
x = a.compress('my_packet1')
# send x
# x was not acked yet, so we must send another packet via the pre_x
compressor
y = pre_x.compress('my_packet2')

Is there a compression object that can do all this?

Ahh, you are trying to "pretune" the compressor before sending a little
bit ... I think C-zlib does this, but I don't know for sure.

- Adam DePrince

Mar 25 '06 #2
Adam DePrince wrote:
On Sat, 2006-03-25 at 03:08 +0200, Eyal Lotem wrote:
Hey.

I have a problem in some network code. I want to send my packets
compressed, but I don't want to compress each packet separately (via
.encode('zlib') or such) but rather I'd like to compress it with regard
to the history of the
compression stream. If I use zlib.compressobj and flush it to get the
packet data, I cannot continue to compress with that stream.
Yes, you can.

Help on built-in function flush:

flush(...)
flush( [mode] ) -- Return a string containing any remaining
compressed data.
mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH,
Z_FINISH; the
default value used when mode is not specified is Z_FINISH.
If mode == Z_FINISH, the compressor object can no longer be used
after
calling the flush() method. Otherwise, more data can still be
compressed.

you want to call

mycompressor.flush( zlib.Z_SYNC_FLUSH )

The difference between the flushes is this:

1. Z_SYNC_FLUSH. This basically send enough data so that the receiver
will get everything you put in. This does decerase your compression
ratio (however, in weird case when I last played with it, it helped.)

2. Z_FULL_FLUSH. This sends enough data so that the receiver will get
everything you put in. This also wipes the compressors statistics, so
the when you pick up where you left of, the compressor will compress
about as well as if you had just started, you are wiping its memory of
what it saw in the past.

3. Z_FINISH. This is the default action, this is what is killing you.

Good luck - Adam DePrince


Thanks! That really helps.

I cannot wait until the end of the stream and then flush, because I need
to flush after every packet.

Another capability I require is to be able to copy the compression
stream. i.e: To be able to create multiple continuations of the same
compression stream. Something like:

a = compressobj()
pre_x = a.copy()
x = a.compress('my_packet1')
# send x
# x was not acked yet, so we must send another packet via the pre_x
compressor
y = pre_x.compress('my_packet2')

Is there a compression object that can do all this?

Ahh, you are trying to "pretune" the compressor before sending a little
bit ... I think C-zlib does this, but I don't know for sure.


Yeah, but I don't need a powerful tuning, just a means to copy the
compressor's state. I guess I'll need to write some C for this.

Thanks again!

- Adam DePrince


Mar 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bangalore | last post by:
Hi In reversing string usring recursive function, i found problems in using incremental postfix , and incremental prefix 1 void rev(char*); 2 void main() 3 { 4 char s="STRING"; 5 ...
1
by: jane | last post by:
HI, I had a question on incremental backup. We had an incremental backup every weekend. We did full backup every other week. That is one week incremental + full , the other week is...
1
by: Jimmy Chen | last post by:
Recently I've done a db2 backup and restore/recovery, but the process for recovering the database was different than what I thought to be. here is what I did: DB2 is set in online mode -...
3
by: apple | last post by:
UDB v8 fp 6a on AIX 5.1.0.0 Below is a manual incremental recover from compressed backup datasets. With external compress backup datasets, can it be coded to do an automatic incremental recover?...
0
by: Willem | last post by:
Based on MK's TSI_SOON (http://www.trigeminal.com/)I've created a nifty little procedure that - whenever you compact you db you get an incremental backup copy. Given that you have a table with...
6
by: Rudy Ray Moore | last post by:
I work with a multi-project workspace. One project (the "startup" project) has a "Configuration Type" of "Application (.exe)". The other 40 projects have a "Configuration Type" of "Static Library...
3
by: Alex Shturm | last post by:
Hi, I am trying to activate incremental link using VC7 (.NET 2003) on a pretty big project (executable size is more than 100Mb, and it gets linked from several dozen of libraries and object...
6
by: Raj | last post by:
How can we do an online restore of a tablespace using the incremental backup's? we are on a partitioned database... Also, how could we use backup copy made by the load (using the copy to option...
8
by: Bern McCarty | last post by:
We have a large mixed dll that I can never seem to get to link incrementally. Below is the console output. For simplicity I've eliminated some stuff that we normally do when we really link this...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.