Информационный сервер для программистов: Исходники со всего света. Паскальные исходники со всего света
  Powered by Поисковый сервер Яndex: Найдется ВСЁ!
На Главную Pascal Форум Информер Страны мира
   Архивы и Архиваторы    >>    lzw1
 DOUGPACK - interpretation of the LZW algorithm   Douglas P. Webb 19.05.1993

Модуль DOUGPACK использует интерпретацию алгоритма LZW для сжатия и распаковки файлов. Приведен пример использования.
The DOUGPACK unit implements an interpretation of the LZW algorithm. Included is a simple 1 file compression program as a demonstration on how to use this unit.


{-------------------------------------------------------------------} {----- Turbo Pascal DOUGPACK unit written by Douglas Webb ------} {-------------------------------------------------------------------} {----- DISCLAIMER: There shall be no guarantee of the ------} {----- suitability of this software for any purpose. The ------} {----- author shall not be liable for any damages arrising ------} {----- from the use of this software. ------} {-------------------------------------------------------------------} This unit was written to demonstrate how LZW compression can be used to compress files. It's ability to do so depends highly on the type of data being compressed. Text files may compress to 30-50% their original size, .EXE files to 60-80% of their original size, database files to 20-40% of their original size, and unpatterned data may actually increase in size. This incarnation of the algorithm is optimized for speed, as much as is possible in a high level language like pascal, and to a lesser degree at this experimental stage, flexibility, not readability. CRC assembly language routines were furnished by: Edwin T. Floyd [76067,747] This unit allows the user to compress data using a variation on the standard LZW compression format, or conversely to decompress data that was previously compressed by this unit. This unit makes a few assumptions: 1) Data being compressed is being sent to a file. 2) Data being decompressed is coming from a file. There are however a number of options as to where the compressed data is coming from, and the decompressed data is going. In fact it requires that you pass the "Compress" procedure a procedural parameter of type 'GetBytesProc' (declared below) which will accept 3 parameters and act in every way like a 'BlockRead' procedure call. Compress will ask for data in chunks of 4K or so at a time. Your procedure should return the data to be compressed: GetBytesProc = PROCEDURE(VAR DTA; NBytes:WORD; VAR Bytes_Got:WORD); DTA is the start of a memory location where the information returned should be. NBytes is the number of bytes requested. The actual number of bytes returned must be passed in Bytes_Got (if there is no more data then 0 should be returned). "Decompress" requires a procedural parameter of type 'PutBytesProc' which will accept 3 parameters, and must act in every way like a 'BlockWrite' procedure call. It must accept the decompressed data and do something with it. GetBytesProc = PROCEDURE(VAR DTA; NBytes:WORD; VAR Bytes_Got: WORD); Don't forget that as procedural parameters they must be compiled in the 'F+' state to avoid a catastrophe. Unpleasant NOTE: My provisions for maintaining a CRC for the compressed file seem to get into trouble if you try to compress/decompress multiple runs of data successively. You'll get a warning that the CRC is bad when in fact results appear to indicate that this is not so. So you may have to ignore the CRC unless you can figure out how it's broken.