-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathCromis.Streams.Filters.ZLIB.pas
88 lines (72 loc) · 1.72 KB
/
Cromis.Streams.Filters.ZLIB.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
unit Cromis.Streams.Filters.ZLIB;
interface
uses
SysUtils, Classes, Zlib,
// cromis units
Cromis.Streams.Filters;
type
TZLIBFilter = class(TCustomFilter)
public
constructor Create;
procedure InputFilter(const InputStream, OutputStream: TStream); override;
procedure OutputFilter(const InputStream, OutputStream: TStream); override;
end;
// filter data constructor
function ZLIBFilter: TCustomFilter;
implementation
function ZLIBFilter: TCustomFilter;
begin
Result := TZLIBFilter.Create;
end;
{ TZLIBFilter }
constructor TZLIBFilter.Create;
begin
FID := 'A6F9B382118148248E10F0597FE69D96';
end;
procedure TZLIBFilter.InputFilter(const InputStream, OutputStream: TStream);
const
BufferSize = 4096;
var
Count: Integer;
ZStream: TCompressionStream;
Buffer: array[0..BufferSize - 1] of Byte;
begin
inherited;
ZStream := TCompressionStream.Create(clMax, OutputStream);
try
while True do
begin
Count := InputStream.Read(Buffer[0], BufferSize);
if Count <> 0 then
ZStream.Write(Buffer[0], Count)
else
Break;
end;
finally
ZStream.Free;
end;
end;
procedure TZLIBFilter.OutputFilter(const InputStream, OutputStream: TStream);
const
BufferSize = 4096;
var
Count: Integer;
ZStream: TDecompressionStream;
Buffer: array[0..BufferSize - 1] of Byte;
begin
inherited;
ZStream := TDecompressionStream.Create(InputStream);
try
while True do
begin
Count := ZStream.Read(Buffer[0], BufferSize);
if Count <> 0 then
OutputStream.WriteBuffer(Buffer[0], Count)
else
Break;
end;
finally
ZStream.Free;
end;
end;
end.