I have serious problem and i'm stuck on this :( I need to transfer from my application big files (sometimes more than 1GB) with process it to another application i.e. TotalCommander or Explorer. To do it i need to read part of file from source file to stream, process it and save to output stream. I can't load entire file i need to read about 1-30MB, process it and save. I'm using Drag Drop component suite for Delphi 7
Sample code (in desperate i try many variations):
Var
F13Stream : TmemoryStream;
Procedure Process_Data;
Var
FileIn : TFileStream;
begin
FileIn := TFileStream.Create('c:\SampleData.dat', fmOpenRead);
Repeat
..read from FileIn, process data
..save to F13Stream
..write F13Stream to output? and free memory to next part data//Sorry i have no idea what to doit :(
Until eof(source_file);
FileIn.Free;
end;
procedure TForm13.OnGetStream(Sender: TFileContentsStreamOnDemandClipboardFormat;
Index: integer; out AStream: IStream);
begin
Form13.F13Stream := TMemorystream.Create;
Process_Data;
try
AStream := nil;
AStream := TFixedStreamAdapter.Create(F13Stream, soOwned);
except
F13Stream.Free;
raise;
end;
end;
procedure TForm13.LMDShellList1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
TVirtualFileStreamDataFormat(DataFormatAdapterSource.DataFormat).FileNames.Clear;
TVirtualFileStreamDataFormat(DataFormatAdapterSource.DataFormat).FileNames.Add('TestFile');
DropEmptySource1.Execute;
end;
This is example what i try to do. Maybe another component/code will do this, without problems. I can copy files without size limitations, but i need partially process big files and partially send to another applications as stream/array only by memory not to using temporary disk drive memory. Thanks for any help.
UPDATE:
procedure TForm13.OnGetStream(Sender: TFileContentsStreamOnDemandClipboardFormat;
Index: integer; out AStream: IStream);
var
plk1 : TFileStream;
buff : array[0..65535] of byte;
read : Longint;
begin
AStream := nil;
Form13.F13Stream := TMemoryStream.Create;
AStream := TFixedStreamAdapter.Create(Form13.F13Stream, soOwned);
plk1 := TFileStream.Create('h:\Sample2GB_file.dat', fmOpenRead);
repeat
read := plk1.Read(buff, 65536);
AStream.Write(@buff, read, PLongint(65536));
AStream.SetSize(0);
until read <> 65536;
plk1.Free;
end;
It also not work. As result i have 0 bytes file output.
UPDATE2:
If i remove line: "AStream.SetSize(0);" then i have "Out of memory" error.