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 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 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; |
function GetEnableNetwork: Boolean; deprecated 'use EnableBlockingDownloads'; |
Warning: this symbol is deprecated: use EnableBlockingDownloads |
procedure SetEnableNetwork(const Value: Boolean); deprecated 'use EnableBlockingDownloads'; |
Warning: this symbol is deprecated: use EnableBlockingDownloads |
function URLSaveStream(const URL: string; const Options: TSaveStreamOptions = []): TStream; |
Create a stream to save a given URL, for example create a TFileStream to save a file for a Right now, this only works for 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 .
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; |
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; |
TDownloadFinishedEvent = procedure (const Sender: TCastleDownload; var FreeSender: Boolean) of object; |
TSaveStreamOption = (...); |
Options for the URLSaveStream function. Values
|
TSaveStreamOptions = set of TSaveStreamOption; |
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; |
Generated by PasDoc 0.16.0.