File: avisozlib.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (74 lines) | stat: -rw-r--r-- 1,530 bytes parent folder | download | duplicates (12)
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
unit avisozlib;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, paszlib;

type
  Decode = class
  public
    procedure CHECK_ERR(err: Integer; msg: String);
     procedure EXIT_ERR(const msg: String);
     function test_inflate(compr: Pointer; comprLen : LongInt;
               uncompr: Pointer; uncomprLen : LongInt): PChar;
     constructor Create();
    end;

implementation

procedure Decode.CHECK_ERR(err: Integer; msg: String);
begin
  if err <> Z_OK then
  begin
    raise Exception.Create('ERROR: ' + msg);
    Halt(1);
  end;
end;

procedure Decode.EXIT_ERR(const msg: String);
begin
  raise Exception.Create('ERROR: ' + msg);
  Halt(1);
end;

function Decode.test_inflate(compr: Pointer; comprLen : LongInt;
                       uncompr: Pointer; uncomprLen : LongInt): PChar;
var err: Integer;
    d_stream: TZStream; // decompression stream
begin
  StrCopy(PChar(uncompr), 'garbage');

  d_stream.next_in := compr;
  d_stream.avail_in := 0;
  d_stream.next_out := uncompr;

  err := inflateInit(d_stream);
  CHECK_ERR(err, 'inflateInit');

  while (d_stream.total_out < uncomprLen) and
        (d_stream.total_in < comprLen) do
  begin
    d_stream.avail_out := 1; // force small buffers
    d_stream.avail_in := 1;
    err := inflate(d_stream, Z_NO_FLUSH);
    if err = Z_STREAM_END then
      break;
    CHECK_ERR(err, 'inflate');
  end;

  err := inflateEnd(d_stream);
  CHECK_ERR(err, 'inflateEnd');

  Result:=PChar(uncompr);
end;

constructor Decode.Create();
begin
  inherited Create;
end;

end.