Developers.Code.CZLib

From Shareaza Wiki
Revision as of 18:16, 31 December 2007 by Dirtycat (talk | contribs) (Importing page from Tikiwiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

CZLib

CZLib is a very small class that has two methods: Compress and Decompress. Each takes a pointer to read data from, and another pointer where the method can write memory. Both methods are static, and the class doesn't have any member variables. This makes them just like C functions.

<source lang="c"> // Compress and decompress nInput bytes at pInput to a new returned buffer of size pnOutput static LPBYTE Compress(LPCVOID pInput, DWORD nInput, DWORD* pnOutput, DWORD nSuggest = 0); static LPBYTE Decompress(LPCVOID pInput, DWORD nInput, DWORD* pnOutput, DWORD nSuggest = 0); </source>

The zlib compression library can do compression two different ways. If you have all the data you want to compress right now, then it can compress it. If instead you have the start of a bunch of data, and want to start compressing it without knowing what data may follow, you need stream compression. The zlib library can do that too, but CZLib can't yet.

It would be great if Shareaza only used the zlib library through CZLib. This isnt' the case at all. There is zlib code here, in CNeighbour, in CBuffer, and sprinkled elsewhere throughout the code. Search z_stream in Visual Studio to find all the places the code deals with zlib stream compression directly.

I've written a refactored CZLib that will stream compression easy for the rest of Shareaza to do. You can check out the code here: [1]