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:
| function CompressStream(inpStream: TMemoryStream): TMemoryStream; var InpBuf, OutBuf: Pointer; InpBytes, OutBytes: Integer; outStream: TMemoryStream; begin InpBuf := nil; OutBuf := nil; outStream:=TMemoryStream.Create; try GetMem(InpBuf, inpStream.Size); inpStream.Position := 0; InpBytes := inpStream.Read(InpBuf^, inpStream.Size); CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes); outStream.Write(OutBuf^, OutBytes); finally if InpBuf <> nil then FreeMem(InpBuf); if OutBuf <> nil then FreeMem(OutBuf); end; result:=outStream; end;
function DecompressStream(inpStream: TMemoryStream): TMemoryStream; var InpBuf, OutBuf: Pointer; OutBytes, sz: Integer; outStream: TMemoryStream; begin InpBuf := nil; OutBuf := nil; outStream:=TMemoryStream.Create; inpStream.Position:=0; sz := inpStream.Size - inpStream.Position; if sz > 0 then try GetMem(InpBuf, sz); inpStream.Read(InpBuf^, sz); DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes); outStream.Write(OutBuf^, OutBytes); finally if InpBuf <> nil then FreeMem(InpBuf); if OutBuf <> nil then FreeMem(OutBuf); end; outStream.Position := 0; Result:=outStream; end; |