Unit CastleDownload
Description
Read and write stream contents from URLs.
Uses
- SysUtils
- Classes
- CastleVectors
Overview
Classes, Interfaces, Objects and Records
Name | Description |
---|---|
Class TUrlAsynchronousReader |
Implement this class, and pass to RegisterUrlProtocol, to read protocols asynchronously (such that TCastleDownload can read them asynchronously). |
Class EProtocolAlreadyRegistered |
|
Class EDownloadError |
|
Class ESaveError |
|
Class TCastleDownload |
Download an URL (possibly making an HTTP(S) request) asynchronously, without blocking the application. |
Class TTextReaderWriter |
Common class for reading or writing a stream like a text file. |
Class TTextReader |
Read any stream like a text file. |
Class TTextWriter |
Write to a stream like to a text file. |
Class TStringsHelper |
Copyright 2013-2020 Michalis Kamburelis. |
Functions and Procedures
procedure RegisterUrlProtocol(const Protocol: String; const ReadEvent: TUrlReadEvent; const WriteEvent: TUrlWriteEvent; const AsynchronousReader: TUrlAsynchronousReaderClass = nil; const DetectMimeTypeFromExtension: Boolean = true); |
function RegisteredUrlProtocol(const Protocol: String): Boolean; |
procedure UnregisterUrlProtocol(const Protocol: String); |
function Download(const Url: String; const Options: TStreamOptions = []): TStream; overload; |
function Download(const Url: String; const Options: TStreamOptions; out MimeType: string): TStream; overload; |
function GetEnableNetwork: Boolean; deprecated 'use EnableBlockingDownloads'; |
procedure SetEnableNetwork(const Value: Boolean); deprecated 'use EnableBlockingDownloads'; |
function UrlSaveStream(const Url: String; const Options: TSaveStreamOptions = []): TStream; |
function CreateReadFileStream(const Url: String): TStream; deprecated 'use Download(Url, [soForceMemoryStream])'; |
procedure StreamSaveToFile(Stream: TStream; const Url: String); |
Types
TDownloadStatus = (...); |
THttpMethod = (...); |
TUrlAsynchronousReaderClass = class of TUrlAsynchronousReader; |
TUrlReadEvent = function ( const Url: String; out MimeType: string): TStream of object; |
TUrlWriteEvent = function(const Url: String): TStream of object; |
TStreamOption = (...); |
TStreamOptions = set of TStreamOption; |
TDownloadFinishedEvent = procedure (const Sender: TCastleDownload; var FreeSender: Boolean) of object; |
TSaveStreamOption = (...); |
TSaveStreamOptions = set of TSaveStreamOption; |
Variables
LogAllLoading: boolean = false; |
EnableBlockingDownloads: boolean = false; |
property EnableNetwork: Boolean read GetEnableNetwork write SetEnableNetwork; |
Description
Functions and Procedures
procedure RegisterUrlProtocol(const Protocol: String; const ReadEvent: TUrlReadEvent; const WriteEvent: TUrlWriteEvent; const AsynchronousReader: TUrlAsynchronousReaderClass = nil; const DetectMimeTypeFromExtension: Boolean = true); |
Register how we can load and/or save the URLs with given protocol. One (or even both) of given events (ReadEvent, WriteEvent) can be
Parameters
Exceptions raised
|
function RegisteredUrlProtocol(const Protocol: String): Boolean; |
Is given protocol name registered with RegisterUrlProtocol. |
procedure UnregisterUrlProtocol(const Protocol: String); |
Unregister protocol, reverting the RegisterUrlProtocol. |
function Download(const Url: String; const Options: TStreamOptions = []): TStream; overload; |
Return a stream to read given URL. Returned stream is suitable only for reading, and the initial position is always at the beginning. Overloaded version also returns a MIME type (or '' if unknown). Any errors are reported by raising exceptions. All the supported URL protocols are documented in our manual: https://castle-engine.io/manual_network.php . They include:
This routine makes a synchronous (blocking) downloading. Which means that if you use a network URL (like http://...) then your application will wait until the data arrives from the Internet. There may be a timeout of the request (so your application will not hang indefinitely), but still your code (or user) have no way to cancel or watch the progress of this operation. This is why http/https support is disabled by default (see EnableBlockingDownloads). This is sometimes acceptable (e.g. if you're waiting during the "loading" process, and the data just has to be downloaded in order to continue), and it's really easy to use (you just download data exactly the same way like you open a local file). You can use asynchronous downloading through the TCastleDownload class instead.
Exceptions raised
|
function Download(const Url: String; const Options: TStreamOptions; out MimeType: string): TStream; overload; |
This item has no description. |
function GetEnableNetwork: Boolean; deprecated 'use EnableBlockingDownloads'; |
Warning: this symbol is deprecated: use EnableBlockingDownloads This item has no description. |
procedure SetEnableNetwork(const Value: Boolean); deprecated 'use EnableBlockingDownloads'; |
Warning: this symbol is deprecated: use EnableBlockingDownloads This item has no description. |
function UrlSaveStream(const Url: String; const Options: TSaveStreamOptions = []): TStream; |
Create a stream to save (write to) a given URL. For example, to save a file. When you use This function supports any CGE custom protocol registered by RegisterUrlProtocol, if only you provided Note: When saving to On Android, you should use the "write_external_storage" service to be able to write storage files (e.g. to SD card). This means files accessed by the 'file' protocol. See https://castle-engine.io/android-Services . Example usage: var Stream: TStream; I: Uint32; begin Stream := URLSaveStream('file:///tmp/foo.txt', []); try // write some strings WritelnStr(Stream, 'Some string'); WritelnStr(Stream, 'Another string'); // write some binary data I := 666; Stream.WriteBuffer(I, SizeOf(I)); finally FreeAndNil(Stream) end; end;
Exceptions raised
|
function CreateReadFileStream(const Url: String): TStream; deprecated 'use Download(Url, [soForceMemoryStream])'; |
Warning: this symbol is deprecated: use Download(Url, [soForceMemoryStream]) Open a proper stream to read a file, fast (with buffering) and with seeking. This gives you a stream most comfortable for reading (buffering means that you can read small, comfortable pieces of it; seeking means you can jump freely to various file positions, back and forward). On different OSes or even compilers this may require a little different stream, so it's safest to just use this function. For example, traditional Classes.TFileStream doesn't do buffering. Although under Linux, the buffering of file handles is done at kernel level (so everything works fast), on Windows the slowdown is noticeable. This function will always create proper stream descendant, eventually wrapping some standard stream in a buffered stream with full seeking capability. Instead of this, use Download with [soForceMemoryStream]. |
procedure StreamSaveToFile(Stream: TStream; const Url: String); |
Save the contents of given Stream to an Url. |
Types
TDownloadStatus = (...); |
Values
|
THttpMethod = (...); |
See TCastleDownload.HttpMethod. Values
|
TUrlAsynchronousReaderClass = class of TUrlAsynchronousReader; |
This item has no description. |
TUrlReadEvent = function ( const Url: String; out MimeType: string): TStream of object; |
Event called when Download function wants to download URL with this protocol. Use with RegisterUrlProtocol. |
TUrlWriteEvent = function(const Url: String): TStream of object; |
Event called when URLSaveStream function wants to save URL with this protocol. Use with RegisterUrlProtocol. |
TStreamOption = (...); |
Options for the Download function. Values
|
TStreamOptions = set of TStreamOption; |
This item has no description. |
TDownloadFinishedEvent = procedure (const Sender: TCastleDownload; var FreeSender: Boolean) of object; |
This item has no description. |
TSaveStreamOption = (...); |
Options for the UrlSaveStream function. Values
|
TSaveStreamOptions = set of TSaveStreamOption; |
This item has no description. |
Variables
LogAllLoading: boolean = false; |
Log (through CastleLog) all loading, that is: all calls to Download. This allows to easily check e.g. whether the engine is not loading something during the game (which usually badly affects the performance). |
EnableBlockingDownloads: boolean = false; |
Does Download (synchronous downloading routine) support http and https protocol. This is by default disabled, as it means that a call to Download may block your application, for arbitrarily long time, and you have no way to interrupt it. It is recommended to use asynchronous downloading, using TCastleDownload, to download resources over the network. |
property EnableNetwork: Boolean read GetEnableNetwork write SetEnableNetwork; |
This item has no description. |
Generated by PasDoc 0.16.0-snapshot.