function Download(const Url: string; const Options: TStreamOptions): TStream;
- The above function is used to load or URL download the file
- I want to know if the TStream it loads is already loaded into memory or if it is loaded in a file handle only format like TFileStream
- I saw your presentation that if you don’t give TStreamOptions a property then it might return TFileStream or TBase64DecodingStream
- I understand whether the local load is TFileStream and the network download is TBase64DecodingStream
- If I am on a non-Windows platform such as IOS or Android and load the file locally is it TFileStream
- How can I use TFileStream to do cross-platform large file data reading without TFileStream
- I hope you can help. Thank you. It means a lot to me
As for reading:
What the Download
function returns may vary between platforms. On some platforms, like Android, it just cannot be a TFileStream. To be cross-platform, you just cannot type-cast the value returned from Download
to a TFileStream, you simply cannot use TFileStream. You have to rely on abstract TStream methods for reading. Or copy the resulting stream contents to something else.
There is one additional option, for convenience: pass to Download
the flag soForceMemoryStream
, in which case you know that you have the TCustomMemoryStream
instance. Like this:
MyMemoryStream := Download('something://something') as TCustomMemoryStream;
As for read-only: indeed, the stream returned by Download
may be read-only. Again, on some platforms, there’s no other choice. On Android or iOS, you cannot modify your game data. On Linux or Windows, with system-wide installation, regular user may also not be able to modify your game data.
Use ApplicationConfig
to get URL where you can store files.
As for writing: Use URLSaveStream
. See also Network, downloading and using URLs | Manual | Castle Game Engine for more information.
In summary, you can save file like this (if you want to use binary streams):
var
SaveStream: TStream;
I: Int32;
begin
SaveStream := URLSaveStream(ApplicationConfig('mysave.bin'));
try
I := 666;
SaveStream.WriteBuffer(I, SizeOf(I));
finally FreeAndNil(SaveStream) end;
end;