Search code examples
delphiziptar

Zip without compression (Delphi)


I am using the TZipFile class provided natively by Delphi and I am wondering if it is possible to pack / unpack without compression, similar to the tar command in unix.In this case, we seek the greatest efficiency in extracting and writing files into a package. Thanks.


Solution

  • Solution: zip-without-compression-delphi

    The key is to use the ZcStored option in the TZipFile.Add procedure.

    Attached is a working example that answers my question, in case anyone falls into the same issue that has been kindly resolved by Tom Brunberg

    // Uses system.zip;

    Procedure MakeZipFile;
    Var
     fZip: TzipFile;
     PathZip, MyPathFile: String;
    begin
     fZip := TZipFile.Create;
     Try
       PathZip := 'C:\example.zip';
       MyPathFile := 'C:\myfile.txt';
       fZip.Open(PathZip, zmWrite);
       fZip.Add(MyPathFile, '', ZcStored); // Thanks Tom
       fZip.Close;
     Finally
       fZip.Free; 
     end;
    end;
    

    Compression type Tzipfile Delphi