Class TDataURI

Unit

Declaration

type TDataURI = class(TObject)

Description

Reading data URI scheme, see http://en.wikipedia.org/wiki/Data_URI_scheme. Such URI specifies the MIME type and contains the data, encoded in plain text or base64. That is, the data is not merely referenced / linked (like with a usual URL), it's simply fully encoded inside the URI. Since such URI can be used anywhere a normal URI is expected, it allows you to inline any kind of data inside any container file. For example, you can place images (textures) and such directly inside a VRML/X3D file.

Hierarchy

  • TObject
  • TDataURI

Overview

Methods

Public destructor Destroy; override;
Public class function IsDataURI(const URI: string; out Colon: Integer): boolean; overload;
Public class function IsDataURI(const URI: string): boolean; overload;
Public function Stream: TStream;
Public function ExtractStream: TStream;

Properties

Public property ForceMemoryStream: boolean read FForceMemoryStream write FForceMemoryStream;
Public property URI: string read FURI write SetURI;
Public property Valid: boolean read FValid;
Public property MimeType: string read FMimeType;
Public property Base64: boolean read FBase64;
Public property Charset: string read FCharset;
Public property URIPrefix: string read FURIPrefix;

Description

Methods

Public destructor Destroy; override;
 
Public class function IsDataURI(const URI: string; out Colon: Integer): boolean; overload;
 
Public class function IsDataURI(const URI: string): boolean; overload;
 
Public function Stream: TStream;

Read the actual data contents. If the URI is not valid (includes the initial state when it's not set) then returns Nil.

The important property of this reader is that no expensive encoding is done until you call this method. In particular, you can set URI, check MimeType, and if you see that MimeType is something not interesting for you (for example, maybe you require some image type) just don't call this method. Then nothing expensive will happen, e.g. data will not be base64-decoded without a need.

Public function ExtractStream: TStream;

Get Stream and clear it. Makes the stream no longer owner by this TDataURI instance.

Do not call Stream after calling ExtractStream. Results are undefined. (Right now, another decoding stream will then be created, that will return the same thing as previous stream. But do not depend on it.)

Properties

Public property ForceMemoryStream: boolean read FForceMemoryStream write FForceMemoryStream;

Force Stream and ExtractStream to return a TMemoryStream, that is always seekable and fully buffered in memory. Without this, they may return TBase64DecodingStream that may not be seekable.

Public property URI: string read FURI write SetURI;

The data URI that this class reads.

When you set this, we read the beginning of URI. If this is a valid data URI, then we set Valid to True, update MimeType, Base64, Charset, URIPrefix accordingly, and you can call Stream if you want to read actual contents.

If this is not a valid data URI, then we set Valid to False, make appropriate warning through WritelnWarning, and reset MimeType, Base64, Charset, URIPrefix to some default values.

Public property Valid: boolean read FValid;
 
Public property MimeType: string read FMimeType;
 
Public property Base64: boolean read FBase64;
 
Public property Charset: string read FCharset;
 
Public property URIPrefix: string read FURIPrefix;

URI without the data, nice to show to user.


Generated by PasDoc 0.16.0.