avisozlib.pas 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. unit avisozlib;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, paszlib;
  6. type
  7. Decode = class
  8. public
  9. procedure CHECK_ERR(err: Integer; msg: String);
  10. procedure EXIT_ERR(const msg: String);
  11. function test_inflate(compr: Pointer; comprLen : LongInt;
  12. uncompr: Pointer; uncomprLen : LongInt): PChar;
  13. constructor Create();
  14. end;
  15. implementation
  16. procedure Decode.CHECK_ERR(err: Integer; msg: String);
  17. begin
  18. if err <> Z_OK then
  19. begin
  20. raise Exception.Create('ERROR: ' + msg);
  21. Halt(1);
  22. end;
  23. end;
  24. procedure Decode.EXIT_ERR(const msg: String);
  25. begin
  26. raise Exception.Create('ERROR: ' + msg);
  27. Halt(1);
  28. end;
  29. function Decode.test_inflate(compr: Pointer; comprLen : LongInt;
  30. uncompr: Pointer; uncomprLen : LongInt): PChar;
  31. var err: Integer;
  32. d_stream: TZStream; // decompression stream
  33. begin
  34. StrCopy(PChar(uncompr), 'garbage');
  35. d_stream.next_in := compr;
  36. d_stream.avail_in := 0;
  37. d_stream.next_out := uncompr;
  38. err := inflateInit(d_stream);
  39. CHECK_ERR(err, 'inflateInit');
  40. while (d_stream.total_out < uncomprLen) and
  41. (d_stream.total_in < comprLen) do
  42. begin
  43. d_stream.avail_out := 1; // force small buffers
  44. d_stream.avail_in := 1;
  45. err := inflate(d_stream, Z_NO_FLUSH);
  46. if err = Z_STREAM_END then
  47. break;
  48. CHECK_ERR(err, 'inflate');
  49. end;
  50. err := inflateEnd(d_stream);
  51. CHECK_ERR(err, 'inflateEnd');
  52. Result:=PChar(uncompr);
  53. end;
  54. constructor Decode.Create();
  55. begin
  56. inherited Create;
  57. end;
  58. end.