Einzelnen Beitrag anzeigen

Benutzerbild von SleepyMaster
SleepyMaster

Registriert seit: 18. Mai 2003
634 Beiträge
 
#1

String komprimieren dekomprimieren

  Alt 16. Mär 2004, 16:15
Delphi-Quellcode:
uses
  ZLib;

function CompressString(input:string):string;
var
  InpBuf, OutBuf: Pointer;
  OutBytes: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  try
    GetMem(InpBuf, Length(input));
    Move(input[1], InpBuf^, Length(input));
    CompressBuf(InpBuf, Length(input), OutBuf, OutBytes);
    SetLength(result,OutBytes);
    Move(OutBuf^, result[1], OutBytes);
  finally
    if InpBuf <> nil then FreeMem(InpBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;

function DeCompressString(input:string):string;
var
  InpBuf, OutBuf: Pointer;
  OutBytes: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  try
    GetMem(InpBuf, Length(input));
    Move(input[1], InpBuf^, Length(input));
    DeCompressBuf(InpBuf, Length(input),0,OutBuf, OutBytes);
    SetLength(result,OutBytes);
    Move(OutBuf^, result[1], OutBytes);
  finally
    if InpBuf <> nil then FreeMem(InpBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;
  Mit Zitat antworten Zitat