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: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131:
| unit Packer;
interface
uses Windows;
procedure CompressFile(FileName: string); overload; procedure CompressFile(sfrom, sto: string); overload; procedure DeCompressFile(FileName: string); overload; procedure DeCompressFile(sfrom, sto: string); overload; procedure DeCompressFile(filename: string; var pout: Pointer); overload; procedure CompressFile(FileName: string; var pin: Pointer); overload;
function FileExists(const FileName: string): Boolean;
implementation
uses ZLib;
procedure DeCompressFile(filename: string; var pout: Pointer); var f: File of byte; pIn: Pointer; sizeRead,sizeWrite: integer; begin pIn := nil; pOut := nil; assignfile(f, FileName); reset(f); try getmem(pIn, FileSize(f)); BlockRead(f, pIn^, FileSize(f), sizeRead); DeCompressBuf(pIn, sizeRead, sizeRead, pOut, sizeWrite); finally if pIn <> nil then freemem(pIn); CloseFile(f); end; end;
function FileExists(const FileName: string): Boolean; var f: TWin32FindData; handle: THandle; begin handle := FindFirstFile(pChar(FileName), f); result := (handle <> INVALID_HANDLE_VALUE); FindClose(Handle); end;
procedure CompressFile(FileName: string; var pin: Pointer); overload; var f: File of byte; pOut: Pointer; sizeRead,sizeWrite: integer; begin pIn := nil; pOut := nil; assignfile(f, FileName); reset(f); try getmem(pIn, FileSize(f)); BlockRead(f, pIn^, FileSize(f), sizeRead); CompressBuf(pIn, sizeRead, pOut, sizeWrite); ReWrite(f); BlockWrite(f, pOut^, sizeWrite); finally if pOut <> nil then freemem(pOut); CloseFile(f); end; end;
procedure CompressFile(FileName: string); overload; var f: File of byte; pIn,pOut: Pointer; sizeRead,sizeWrite: integer; begin pIn := nil; pOut := nil; assignfile(f, FileName); reset(f); try getmem(pIn, FileSize(f)); BlockRead(f, pIn^, FileSize(f), sizeRead); CompressBuf(pIn, sizeRead, pOut, sizeWrite); ReWrite(f); BlockWrite(f, pOut^, sizeWrite); finally if pIn <> nil then freemem(pIn); if pOut <> nil then freemem(pOut); CloseFile(f); end; end;
procedure DeCompressFile(FileName: string); overload; var f: File of byte; pIn,pOut: Pointer; sizeRead,sizeWrite: integer; begin pIn := nil; pOut := nil; assignfile(f, FileName); reset(f); try getmem(pIn, FileSize(f)); BlockRead(f, pIn^, FileSize(f), sizeRead); DeCompressBuf(pIn, sizeRead, sizeRead, pOut, sizeWrite); ReWrite(f); BlockWrite(f, pOut^, sizeWrite); finally if pIn <> nil then freemem(pIn); if pOut <> nil then freemem(pOut); CloseFile(f); end; end;
procedure CompressFile(sfrom, sto: string); overload; begin if FileExists(sto) then DeleteFile(pchar(sto)); CopyFile(pchar(sfrom), pchar(sto), true); CompressFile(sto); end;
procedure DeCompressFile(sfrom, sto: string); overload; begin if FileExists(sto) then DeleteFile(pchar(sto)); CopyFile(pchar(sfrom), pchar(sto), true); DeCompressFile(sto); end;
end. |