HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Component compress.algorithm.StreamCompression:deflate by barry
expand copy to clipboardexpand
interface ZLib {
	
	int deflateInit()
	byte[] deflate(int stream, byte content[], bool lastChunk)
	void deflateEnd(int stream)
	
	int inflateInit()
	byte[] inflate(int stream, byte content[])
	byte inflateStatus(int stream)
	int inflateEnd(int stream)
	
	}

component provides StreamCompression:deflate requires native ZLib zl {
	
	int cstreamID
	int dstreamID
	
	Mutex compressLock = new Mutex()
	Mutex decompressLock = new Mutex()
	
	void StreamCompression:compressInit()
		{
		mutex(compressLock)
			{
			if (cstreamID != 0)
				{
				throw new Exception("compression instance already initialised")
				}
			
			cstreamID = zl.deflateInit()
			}
		}
	
	byte[] StreamCompression:compress(byte chunk[], bool lastChunk)
		{
		mutex(compressLock)
			{
			return zl.deflate(cstreamID, chunk, lastChunk)
			}
		}
	
	void StreamCompression:compressEnd()
		{
		mutex(compressLock)
			{
			zl.deflateEnd(cstreamID)
			cstreamID = 0
			}
		}

	void StreamCompression:decompressInit()
		{
		mutex(decompressLock)
			{
			if (dstreamID != 0)
				{
				throw new Exception("decompression instance already initialised")
				}
			
			dstreamID = zl.inflateInit()
			}
		}
	
	byte[] StreamCompression:decompress(byte chunk[])
		{
		mutex(decompressLock)
			{
			return zl.inflate(dstreamID, chunk)
			}
		}
	
	byte StreamCompression:decompressStatus()
		{
		mutex(decompressLock)
			{
			return zl.inflateStatus(dstreamID)
			}
		}
	
	int StreamCompression:decompressEnd()
		{
		mutex(decompressLock)
			{
			int q = zl.inflateEnd(dstreamID)
			dstreamID = 0
			return q
			}
		}
	
	}
Revision history
To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n compress.algorithm.StreamCompression:deflate -m "reason for update" -u yourUsername
Version 1 (this version) by barry
Notes for this version: Standard Library Initialisation