THPDFRandomAccessSource Class
Abstract base class that lets THotPDF.LoadFromRandomAccessSource load a PDF from any caller-defined seekable byte store without requiring a TStream implementation
Declaration
THPDFRandomAccessSource = class
public
function GetSize: Int64; virtual; abstract;
function IsRangeAvailable(Offset, Count: Int64): Boolean; virtual;
function ReadAt(Offset: Int64; var Buffer;
Count: Longint): Longint; virtual; abstract;
function ReadAtCancellable(Offset: Int64; var Buffer;
Count: Longint; CancellationToken: THPDFCancellationToken): Longint; virtual;
function TransferAt(Offset, Count: Int64;
Destination: TStream): Int64; virtual;
end;
Unit
HPDFDoc
Members
| Name | Purpose |
|---|---|
GetSize | Returns the stable byte length of the backing store |
ReadAt | Reads Count bytes starting at Offset into Buffer |
IsRangeAvailable | Reports whether a range can be read without waiting for additional data |
ReadAtCancellable | Provides a cooperative cancellation path for remote or otherwise blocking reads |
TransferAt | Writes a source range to a destination stream with a bounded fallback implementation |
Usage notes
- Derive a subclass and override both abstract methods to adapt HotPDF to HTTP range requests, database BLOBs, compressed archives, encrypted volumes, or any virtual storage that can supply bytes by offset
GetSizemust return a stable, non-negative byte length for the lifetime of the load; HotPDF parses the cross-reference tables and object streams by seeking through this sourceReadAtreturns the number of bytes actually transferred (zero throughCount); the parser treats a short read at the documented end of file as end-of-stream, not as an error- The default
ReadAtCancellableimplementation checks the supplied token before and after delegating toReadAt; remote implementations should override it to abort transport work while a request is in flight - The default
TransferAtimplementation uses a bounded 64 KiB buffer; storage adapters can override it to write from retained source memory directly THPDFCoalescingRandomAccessSourceadds bounded range caching, request coalescing, asynchronous prefetch, cancellation, and statistics around any source- The source must remain valid while the loaded document is in use; pass
OwnsSource = Trueto LoadFromRandomAccessSource to have HotPDF free the source automatically