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: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:
| uses zlib;
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); outStream.Write(OutBuf^, OutBytes); finally if InpBuf <> nil then FreeMem(InpBuf); if OutBuf <> nil then FreeMem(OutBuf); end; end;
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); outStream.Write(OutBuf^, OutBytes); finally if InpBuf <> nil then FreeMem(InpBuf); if OutBuf <> nil then FreeMem(OutBuf); end; outStream.Position := 0; end;
procedure savememoryliste(liste:tstringlist;const dateiname:string); var ms1, ms2: TMemoryStream; begin ms1 := TMemoryStream.Create; try ms2 := TMemoryStream.Create; try liste.SaveToStream(ms1); CompressStream(ms1, ms2); ms2.SaveToFile(dateiname); finally ms2.Free; end; finally ms1.Free; end; end;
procedure loadmemoryliste(liste:tstringlist;const dateiname:string); var ms1, ms2: TMemoryStream; begin ms1 := TMemoryStream.Create; try ms2 := TMemoryStream.Create; try ms1.LoadFromFile(dateiname); DecompressStream(ms1, ms2); liste.LoadFromStream(ms2); finally ms2.Free; end; finally ms1.Free; end; end; |