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:
| procedure CompOrUncomp(var Stream : TMemoryStream; Komp : Boolean); var myStream : TMemorystream;
procedure DecompressStream(inpStream, outStream: TStream); var InpBuf, OutBuf: Pointer; OutBytes, sz: Integer; begin InpBuf := nil; OutBuf := nil; sz := inpStream.Size - inpStream.Position; if sz > 0 then try GetMem(InpBuf, sz); inpStream.Read(InpBuf^, sz); DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes); //Fehler ?! outStream.Write(OutBuf^, OutBytes); finally if InpBuf <> nil then FreeMem(InpBuf); if OutBuf <> nil then FreeMem(OutBuf); end; outStream.Position := 0; end;
procedure CompressStream(inpStream, outStream: TStream); var InpBuf, OutBuf: Pointer; InpBytes, OutBytes: Integer; begin InpBuf := nil; OutBuf := nil; try GetMem(InpBuf, inpStream.Size); inpStream.Position := 0; InpBytes := inpStream.Read(InpBuf^, inpStream.Size); CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes); //Fehler ?! outStream.Write(OutBuf^, OutBytes); finally if InpBuf <> nil then FreeMem(InpBuf); if OutBuf <> nil then FreeMem(OutBuf); end; end;
begin myStream := TMemorystream.create; if Komp then CompressStream(Stream,myStream) else DeCompressStream(Stream,myStream); Stream.Size := myStream.Size; Stream.LoadFromStream(myStream); Stream.Position := 0; FreeAndNil(mystream); end; |