Flow decompression and compression (code streamlined and efficient)

zhaozj2021-02-16  51

Use a function to realize the compression and decompression of the stream, how to use:

ZIP (source, target stream, true / false "is compressed, FALSE is unzipped

The function is as follows:

function ZIP (mInputStream: TStream; mOutputStream: TStream; Compress: BOOL): BOOL; var I: Integer; p: pchar; TCS: TCompressionStream; TDS: TDecompressionStream; begin result: = false; if not (Assigned (mInputStream) and Assigned (mOutputStream)) then Exit; try if compress then TCS: = TCompressionStream.Create (clMax, mOutputStream) else TDS: = TDecompressionStream.Create (mOutputStream); // where CLmax represents the compression level can be changed, the value of the following parameters a: clNone, clFastest, clDefault, clMax getMem (p, mInputStream.size); mInputStream.ReadBuffer (p ^, mInputStream.Size); if Compress then TCS.WriteBuffer (p ^, mInputStream.Size) else TDS.WriteBuffer (p ^, MinputStream.size); // Key code: Write Finally if Compress the TCS.Free else tds.free; FreeMem (P); End; RESULT: = true;

First, Uses Zlib this unit, it provides compression and decompression function under Delphi

转载请注明原文地址:https://www.9cbs.com/read-21915.html

New Post(0)