473,434 Members | 1,807 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,434 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 2233
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.