TZipFile Saga Continued

@lexdeanair

Is this something like, or some part of what you want to do?

  • I read in the files from a compressed zipfile
  • I save the data in a MemoryStream
  • I keep a record of where each file ends, and the names
  • I write them out to another Zip file, but uncompressed
{$APPTYPE CONSOLE}
program Project_Zip;

uses
  System.SysUtils, System.Classes, System.Zip;

var
      Bytes     : TBytes;

begin
    var FZip := TZipFile.Create;
        FZip.Open('..\..\nc-e.zip', zmRead);    //  39 files

    var MemStrm := TMemoryStream.Create;

    var fc      := FZip.FileCount;
    var fnames  :  TArray<string>;
    var fend    :  TArray<integer>;

        setlength(fnames, fc);
        setlength(fend,   fc);

        for var i:= 0 to fc-1 do begin          //  read in the zipped files

                FZip.Read(i, Bytes);
                MemStrm.Write(Bytes, length(Bytes) );
                fend[i]   := MemStrm.Position;
                fnames[i] := FZip.FileName[i];
        end;
        FZip.Close;

        FZip.Open('..\..\nc-uncompressed.zip', zmWrite);
    var last_position    := 0;
        MemStrm.Position := 0;

        for var i:= 0 to fc-1 do begin          //  write out the files 
                                                //                uncompressed
                setlength(Bytes, fend[i] - last_position);
                MemStrm.Read(Bytes, length(Bytes) );

                FZip.Add( Bytes, fnames[i], zcStored);
                last_position := fend[i];
        end;
        FZip.Close;

        FZip.Free;
        MemStrm.Free;
        readln;
end.