📄 lzo.pas
字号:
unit Lzo;
interface
uses Windows;
// "C" routines needed by the linked LZO OBJ file
function _memcmp (s1,s2: Pointer; numBytes: LongWord): integer; cdecl;
procedure _memcpy (s1, s2: Pointer; n: Integer); cdecl;
procedure _memmove(dstP, srcP: pointer; numBytes: LongWord); cdecl;
procedure _memset (s: Pointer; c: Byte; n: Integer); cdecl;
{$LINK 'minilzo.obj'}
//obj引用的函数
function _lzo1x_1_compress(const Source: Pointer; SourceLength: LongWord;
Dest: Pointer; var DestLength: LongWord; WorkMem: Pointer): integer; cdecl; external;
function _lzo1x_decompress(const Source: Pointer; SourceLength: LongWord;
Dest: Pointer; var DestLength: LongWord; WorkMem: Pointer (* WORKMEM NOT USED! *)): Integer; cdecl; external;
function _lzo1x_decompress_safe(const Source: Pointer; SourceLength: LongWord;
Dest: Pointer; var DestLength: LongWord; WorkMem: Pointer (* WORKMEM NOT USED! *)): Integer; cdecl; external;
function _lzo_adler32(Adler: LongWord; const Buf: Pointer; Len: LongWord): LongWord; cdecl; external;
function _lzo_version: word; cdecl; external;
function _lzo_version_string: PChar; cdecl; external;
function _lzo_version_date: PChar; cdecl; external;
//使用的接口函数
function CompressData(pData: pointer; dwLen: DWord; pRes: pointer): Longint;
//使用的解压接口函数
function DecompressData(pData: pointer; dwLen: DWord; pRes: pointer): Longint;
implementation
var
WorkMem: Pointer;
procedure _memset(s: Pointer; c: Byte; n: Integer); cdecl;
begin
FillChar(s^, n, c);
end;
procedure _memcpy(s1, s2: Pointer; n: Integer); cdecl;
begin
Move(s2^, s1^, n);
end;
function _memcmp (s1, s2: Pointer; numBytes: LongWord): integer; cdecl;
var
i: integer;
p1, p2: ^byte;
begin
p1 := s1;
p2 := s2;
for i := 0 to numBytes -1 do
begin
if p1^ <> p2^ then
begin
if p1^ < p2^ then
Result := -1
else
Result := 1;
exit;
end;
inc(p1);
inc(p2);
end;
Result := 0;
end;
procedure _memmove(dstP, srcP: pointer; numBytes: LongWord); cdecl;
begin
Move(srcP^, dstP^, numBytes);
FreeMem(srcP, numBytes);//不能取消,否则会影响效率
end;
//========================使用的函数定义=============================
//使用的压缩接口函数
function CompressData(pData: pointer; dwLen: DWord; pRes: pointer): Longint;
var
DestLen: DWord;
begin
result := -1;
if _lzo1x_1_compress(pData, dwLen, pRes, DestLen, WorkMem) = 0 then
result := DestLen;
end;
//使用的解压接口函数
function DecompressData(pData: pointer; dwLen: DWord; pRes: pointer): Longint;
var
DestLen: DWord;
begin
result := -1;
if _lzo1x_decompress(pData, dwLen, pRes, DestLen, nil) = 0 then
result := DestLen;
end;
initialization
GetMem(WorkMem, 65536);
finalization
FreeMem(WorkMem);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -