[P&AM Lab] LZW simple in-memory compression library

Grigoriy A. Sitkarev sitkarev �� komitex.ru
�� ��� 8 02:46:23 MSK 2012


����������� ����.

� ����� �����, ��� � ��� ��������� ������ ���������� � ������� 
����������� ��������� ������ LZW, ��� ������� �� ������� �������� �� 
����� ����������� � ����� � ����������� ������-����������.

��� ����� ����� ��� ����� svn

$ svn co http://wiki.syktsu.ru/svn/libslzw

��� �������� �� ����� websvn ����� HTTP

http://wiki.syktsu.ru/websvn/listing.php?repname=libslzw&path=%2F&sc=0

����������� ��������� ���������� LZW �� �������� in-memory, � 
������������� ��� ������/���������� ������. ��� ����� ���� ���������� 
������ ���������, ������� ��� �� ������������� � ������������ ����� 
������ ������, �� ���� �� �����������.

������� ������������� ���� � encode.c � decode.c. ������� ������ � 
���������� ������ ������ �� ��������� iconv(3). ��� ������� ��������� 5 
����������: ��������, ��������� �� ����� � �������� ������� � ��������� 
�� �� ������, ��������� �� ����� � ��������� ������� � ��������� �� ��� 
������.

����� ������-������, �������������� ������:


#define BUFSIZE	2048

unsigned char buffer[BUFSIZE];
unsigned char buffer2[2*BUFSIZE];
const unsigned char *in;
unsigned char *out;
size_t insz, outsz;
int count, rc;

...

while ((count = read(0, buffer, sizeof(buffer))) > 0) {

	in = buffer;
	insz = count;

	while (insz > 0) {

		out = buffer2;
		outsz = sizeof(buffer2);

		rc = lzw_encode(&enc, &in, &insz, &out, &outsz);

		if (rc == LZW_OK || rc == LZW_NOSPACE) {
			
			/* ����� buffer2 �������� (buffer2 - out)
			 * ������ ����, ������� ����� ��������.
			 */
			...
		} else {

			if (rc == LZW_NOMEM) {
				/* �� ������� ������. */
				...
			} else {
				/* �����-�� ������ ����������... */
				...
			}
		}
	}

	...
}


��������� ������� ������ ������ ������ ������������� ������� 
lzw_end_of_data():


	rc = lzw_end_of_data(&enc, &out, &outsz);
	assert(rc == LZW_OK);

	/* � ����� ������ ��������� ����������� ������������������. */


� ����������� �ӣ �����, ������ decode.c � ������. ���� ��������� ������ 
����������: ��������� �������� ���������� ���������� �������������. � 
����� ������ ������� ������� ��������� ��� �������� LZW. ������ �ӣ 
������ �� ���� �����.

�������� ���������� �� ������ ������ Calgary � ������� ��������� 
������������ ������ ~2.11. ���, ����������, �� ����� ������ ���������, 
�� ��� �� ����������� ���������, �������� �������� ���������� � 
�������������� �������� ������ �������. �������� �������� ��������� 
�������� � test.sh.

����� ����������,
--
�.�.




��������� ���������� � ������ �������� Lab