Reading and Writing binary file of 7 GBytes

2

How can I read and write a binary file of more than 7 GBytes?

The assign (f, 'xx' and the reset (f) work but when I am going to start the file path, the function eof (f) does not work properly, I understand that it is because the TFileRec structure has the fields BufPos and BufEnd defined as cardinal and can only represent up to 4 GBytes.

What function group can I use to perform the operation described?

procedure TForm1.BtnSplitClick1(Sender: TObject);
Var
  F,G : File Of RecCustom;
begin
  System.Assign(F,'NameInputF');
  System.Reset(F);
  System.Assign(F,'NameOutputF');
  System.Reset(F);
  while Not System.Eof(F) Do Begin
    BlockRead(F,Arr,1);
    // Modifica record Arr
    BlockWrite(G,Arr,1);
  End;
  System.Close(F);
end;

Thanks

    
asked by GBM 28.11.2018 в 22:46
source

1 answer

1

The functions assign() , reset() and similar date back many years and, perhaps for reasons of compatibility, have not been updated to support the characteristics of modern file systems, for example, such large files (which before they were simply unthinkable).

Delphi provides a series of classes from which you can pull to build a modern, object-oriented solution to process files the way you want. The most basic, it would be using TFileStream , for example, adapting your code, it could be something in the line of:

var
  Origen, Destino: TFileStream;
  ARec: RecCustom;
  NumRegistros, I: Int64;
begin
  Origen := TFileStream.Create('Entrada.dat', fmOpenRead);
  try
    Destino := TFileStream.Create('Salida.dat', fmCreate);
    try
      NumRegistros := Origen.Size div SizeOf(ARec);
      for I := 1 to NumRegistros do
      begin
        Origen.ReadBuffer(ARec, SizeOf(ARec));
        ModificarRegistro(ARec);
        Destino.WriteBuffer(ARec, SizeOf(ARec));
      end;
    finally
      Destino.Free;
    end;
  finally
    Origen.Free;
  end;
end;
    
answered by 28.11.2018 в 23:06