RAM & File Streams   (HStreams unit)

ThStream

Base class for file and memory streams. It supplies typed reads and writes, text operations, copying, search and format checks.
Its own Read and Write return zero; use a concrete descendant for data I/O.

Clear

Requests a stream size of zero and clears Error_On_Last_IO.
For a protected ThMemoryStream, the size setter refuses to resize, so check Size if clearing must succeed.
procedure ThStream.Clear;

Read

Base implementation reads no bytes. Descendants return the number of bytes actually read, which can be smaller than Count at EOF.
function ThStream.Read(var Buffer; Count: Cardinal): Cardinal; virtual;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Cardinal.

Return Value

Returns the number of bytes transferred; check it against Count.

Write

Base implementation writes no bytes. Descendants return the number of bytes actually written.
function ThStream.Write(const Buffer; Count: Cardinal): Cardinal; virtual;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Cardinal.

Return Value

Returns the number of bytes transferred; check it against Count.

Read_Byte

Reads one byte. On a short read it sets Error_On_Last_IO and returns zero; zero can also be valid data.
function ThStream.Read_Byte: Byte;

Return Value

Returns Byte.

Write_Byte

Writes one byte and returns success status.
function ThStream.Write_Byte(const Value: Byte): Boolean;

Parameters

  • Value: Byte.

Return Value

Returns Boolean.

Read_Word

Reads two bytes into a Word in native byte order. On a short read it sets Error_On_Last_IO and returns zero.
function ThStream.Read_Word: Word;

Return Value

Returns Word.

Write_Word

Writes 2 bytes as Word.
function ThStream.Write_Word(const Value: Word): Boolean;

Parameters

  • Value: Word.

Return Value

Returns Boolean.

Read_Double

Reads eight bytes into a Double in native byte order. On a short read it sets Error_On_Last_IO and returns zero.
function ThStream.Read_Double: Double;

Return Value

Returns Double.

Write_Double

Writes 8 bytes as Double.
function ThStream.Write_Double(Value: Double): Boolean;

Parameters

  • Value: Double.

Return Value

Returns Boolean.

Read_Extended (Win32)

Win32 only. Reads a 10-byte Extended value; returns zero on a short read.
function ThStream.Read_Extended: Extended;

Return Value

Returns Extended.

Write_Extended (Win32)

Win32 only. Writes a 10-byte Extended value. Use the Double methods for new stream formats.
function ThStream.Write_Extended(Value: Extended): Boolean;

Parameters

  • Value: Extended.

Return Value

Returns Boolean.

Init_UCS2_Stream

Sets Position to zero and writes the little-endian UTF-16 BOM FF FE. Subsequent position is after the BOM.
procedure ThStream.Init_UCS2_Stream;

Check_Stream_Is_UCS2

Checks for FF FE at the start. On success Position is after the BOM; on failure Position is reset to zero.
function ThStream.Check_Stream_Is_UCS2: Boolean;

Return Value

Returns Boolean.

Init_UTF8_Stream

Sets Position to zero and writes the UTF-8 BOM EF BB BF. Subsequent position is after the BOM.
procedure ThStream.Init_UTF8_Stream;

Check_Stream_Is_UTF8

Checks for EF BB BF at the start. On success Position is after the BOM; on failure Position is reset to zero.
function ThStream.Check_Stream_Is_UTF8: Boolean;

Return Value

Returns Boolean.

Check_Stream_Is_Windows_Portable_Executable

Checks both the MZ header and the PE signature at the offset stored in the DOS header. Position is reset to zero.
function ThStream.Check_Stream_Is_Windows_Portable_Executable: Boolean;

Return Value

Returns Boolean.

Check_Stream_Is_Zlib_Compressed

Checks a leading 78 byte and the proprietary CD AB 89 footer bytes expected by this unit. Position is reset to zero.
function ThStream.Check_Stream_Is_Zlib_Compressed: Boolean;

Return Value

Returns Boolean.

Read_WideText

Reads at most ReadLength UTF-16 code units from the current position. Text ends at the first null code unit.
function ThStream.Read_WideText(ReadLength: Cardinal): String; virtual;

Parameters

  • ReadLength: Cardinal.

Return Value

Returns String.

Write_WideText

Writes UTF-16 code units. WriteLength counts characters; zero uses Length(Value). Shorter values are padded with Fill.
function ThStream.Write_WideText(const Value: String; WriteLength: Cardinal = 0; Fill: Byte = 0): Boolean; virtual;

Parameters

  • Value: String.
  • WriteLength: Cardinal = 0.
  • Fill: Byte = 0.

Return Value

Returns Boolean.
A fixed WriteLength truncates a longer Value. Fill is written as the padding value.

Read_AnsiText

Reads at most ReadLength bytes into a RawByteString. Text ends at the first null byte.
function ThStream.Read_AnsiText(ReadLength: Cardinal): RawByteString; virtual;

Parameters

  • ReadLength: Cardinal.

Return Value

Returns RawByteString.

Write_AnsiText

Writes RawByteString bytes. WriteLength counts bytes; zero uses Length(Value). Shorter values are padded with Fill.
function ThStream.Write_AnsiText(const Value: RawByteString; WriteLength: Cardinal = 0; Fill: Byte = 0): Boolean; virtual;

Parameters

  • Value: RawByteString.
  • WriteLength: Cardinal = 0.
  • Fill: Byte = 0.

Return Value

Returns Boolean.
A fixed WriteLength truncates a longer Value. Fill is written as the padding byte.

Example

var
  MS: ThMemoryStream;
begin
  MS := ThMemoryStream.Create;
  try
    MS.Write_AnsiText('AB', 4, 0); // Writes $41 $42 $00 $00.
    MS.Position := 0;
    // Read_AnsiText(4) returns 'AB' and advances Position to 4.
  finally
    MS.Free;
  end;
end;

Write_AnsiLine

Writes an ANSI line plus CRLF.
function ThStream.Write_AnsiLine(const Text: RawByteString): Boolean;

Parameters

  • Text: RawByteString.

Return Value

Returns Boolean.

CopyFrom (ThStream source)

Copies from the source current position into this stream. A nonpositive Count rewinds the source and copies its whole content.
function ThStream.CopyFrom(Source: ThStream; Count: Int64; SlowerCopy: Boolean = False): Int64;

Parameters

  • Source: ThStream.
  • Count: Int64; a positive value is capped at the source bytes remaining.
  • SlowerCopy: Boolean = False.

Return Value

Returns the number of bytes copied.

CopyFrom (TStream source)

Copies from a Delphi TStream into this stream. A nonpositive Count rewinds the source and copies its whole content.
function ThStream.CopyFrom(Source: TStream; Count: Int64): Int64;

Parameters

  • Source: TStream.
  • Count: Int64; a positive value is capped at the source bytes remaining.

Return Value

Returns the number of bytes copied.

Pos_AnsiStr

Searches byte offsets FromPos..ToPos and returns a zero-based position, or -1 if no match exists.
function ThStream.Pos_AnsiStr(FindString: RawByteString; FromPos: Int64; ToPos: Int64 = 0; CaseSensitive: Boolean = False): Int64;

Parameters

  • FindString: RawByteString.
  • FromPos: Int64.
  • ToPos: Int64 = 0.
  • CaseSensitive: Boolean = False.

Return Value

Returns the zero-based byte offset, or -1 when absent. The original Position is restored
ToPos = 0 searches through the final byte. Empty patterns and patterns longer than 1000 characters are rejected.

Pos_WideStr

Searches UTF-16 text by byte offset and returns a zero-based position, or -1 if no match exists.
function ThStream.Pos_WideStr(FindString: String; FromPos: Int64; ToPos: Int64 = 0; CaseSensitive: Boolean = False): Int64;

Parameters

  • FindString: String.
  • FromPos: Int64.
  • ToPos: Int64 = 0.
  • CaseSensitive: Boolean = False.

Return Value

Returns the zero-based byte offset, or -1 when absent. The original Position is restored
FromPos and ToPos are byte offsets, not character indexes. ToPos = 0 searches through the final byte.

Calc_CRC_Word

Calculates a fast 16-bit checksum by XORing selected two-byte words. This is not a standard CRC algorithm.
By default, streams up to 3072 bytes are sampled from the start; larger streams are sampled near the start, middle and end. Pass both positions to select a range. The original stream position is restored.
function ThStream.Calc_CRC_Word(ExFromPos: Int64 = -1;
  ExUntilPos: Int64 = -1): Word;
Returns the checksum, or zero when the stream has fewer than two bytes.

Delete

Removes Count bytes beginning at the zero-based FromPos, shifting following bytes left.
function ThStream.Delete(FromPos, Count: Int64): Boolean;

Parameters

  • FromPos, Count: Int64.

Return Value

Returns Boolean.
Returns False for an invalid range or an incomplete copy. Deleting through EOF truncates the stream.

Adapter

Returns a lazily-created ThDelphiStreamAdapter wrapper for VCL/FMX APIs expecting TStream.
function ThStream.Adapter: ThDelphiStreamAdapter;

Return Value

Returns ThDelphiStreamAdapter.

Example

var
  MS: ThMemoryStream;
  Lines: TStringList;
begin
  MS := ThMemoryStream.Create;
  Lines := TStringList.Create;
  try
    MS.Write_AnsiText('First line' + #13#10 + 'Second line');
    MS.Position := 0;
    Lines.LoadFromStream(MS.Adapter);
  finally
    Lines.Free;
    MS.Free;
  end;
end;
The adapter belongs to the stream. Do not use it after freeing the stream.

Properties

Core runtime properties for every stream instance.

property ThStream.Position: Int64 read GetPosition write SetPosition;
property ThStream.Size: Int64 read GetSize write SetSize;
property ThStream.Error_On_Last_IO: Boolean read _Last_IO_Error;

Property Details

  • ThStream.Position: base getter returns zero; descendants supply the actual cursor. File and memory streams clamp an assigned position to 0..Size.
  • ThStream.Size: base getter returns zero; descendants supply the actual size and resize behavior.
  • ThStream.Error_On_Last_IO: read-only error flag set by several read/write operations; Clear resets it. Check the specific operation return value as well.

Setter Logic In Descendants

  • ThFileStream.SetPosition: clamps to EOF when value is above file size.
  • ThFileStream.SetSize: truncates/extends file using OS API and keeps cursor inside bounds.
  • ThMemoryStream.SetPosition: clamps to range 0..Size.
  • ThMemoryStream.SetSize: blocked on protected streams; reallocates by capacity tiers and resets stream on allocation failure.

ThDelphiStreamAdapter

Bridge class that adapts ThStream to native Delphi TStream contract.

Read

Delegates a TStream read to the owner ThStream.
function ThDelphiStreamAdapter.Read(var Buffer; Count: Integer): Integer; override;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Integer.

Return Value

Returns Integer.

Write

Delegates a TStream write to the owner ThStream.
function ThDelphiStreamAdapter.Write(const Buffer; Count: Integer): Integer; override;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Integer.

Return Value

Returns Integer.

Seek (Integer overload)

Moves the owner Position relative to beginning, current position or end and returns the resulting position.
function ThDelphiStreamAdapter.Seek(Offset: Integer; Origin: Word): Integer; override;

Parameters

  • Offset: Integer.
  • Origin: Word.

Return Value

Returns Integer.

Seek (Int64 overload)

Moves the owner Position relative to beginning, current position or end and returns the resulting position.
function ThDelphiStreamAdapter.Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;

Parameters

  • Offset: Int64.
  • Origin: TSeekOrigin.

Return Value

Returns Int64.

GetSize / SetSize

Size accessors forwarded to owner stream in both Integer and Int64 signatures.

function ThDelphiStreamAdapter.GetSize: Int64; override;
procedure ThDelphiStreamAdapter.SetSize(NewSize: Integer); override;
procedure ThDelphiStreamAdapter.SetSize(const NewSize: Int64); override;

Parameters

  • NewSize: target size for SetSize overloads.

Return Value

ThDelphiStreamAdapter.GetSize returns current owner size.
Both SetSize overloads have no return value and delegate to owner stream.

ThFileStream

File-backed stream implementation on top of Windows file handles.

OpenFileStream

Creates a file stream and opens the file. The function sets FS to nil on failure.
Use this function instead of constructing ThFileStream directly: its constructor does not open a file.
type
  ThFileStream_Access = (he_ReadFile, he_UpdateFile, he_CreateNewFile);

function OpenFileStream(FileName: String; Access: ThFileStream_Access;
  var FS: ThFileStream): Boolean;

Access modes

  • he_ReadFile opens an existing file for reading and permits other readers and writers.
  • he_UpdateFile opens for reading and writing with exclusive access; creates the file if it does not exist.
  • he_CreateNewFile creates an empty file, replacing any existing file, with exclusive access.
Returns True if the file was opened. Free FS when finished.

Example

var
  FS: ThFileStream;
  FirstByte: Byte;
begin
  if OpenFileStream('C:\Data\sample.bin', he_ReadFile, FS) then
    try
      if FS.Size > 0 then
        FirstByte := FS.Read_Byte;
    finally
      FS.Free;
    end;
end;

OpenFileStream_Adv

Opens a file with retries. The basic OpenFileStream calls this helper with one attempt and no size limit.
function OpenFileStream_Adv(FileName: String; Access: ThFileStream_Access;
  var FS: ThFileStream; Attempts, SleepBetween: Integer;
  Rename_Max_Size: Int64 = 0): Boolean;
Attempts is clamped to a positive range; SleepBetween is clamped to 20..1000 milliseconds. Retries occur only for sharing, locking, access-denied and mapped-file errors.
When updating a file, a Rename_Max_Size of at least 1 MB causes the function to rename a file that has reached that size and try opening a replacement. A value of zero disables this behavior.
Returns True on success. On failure, FS is nil.

Goto_EOF

Moves current position to end-of-file for append scenarios.
procedure ThFileStream.Goto_EOF;

Read

Reads bytes from file handle at current stream position.
function ThFileStream.Read(var Buffer; Count: Cardinal): Cardinal; override;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Cardinal.

Return Value

Returns the number of bytes transferred; check it against Count.

Write

Writes bytes to file handle at current stream position.
function ThFileStream.Write(const Buffer; Count: Cardinal): Cardinal; override;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Cardinal.

Return Value

Returns the number of bytes transferred; check it against Count.

ThMemoryStream

In-RAM stream with custom allocator, direct buffer access, network helpers, compression, and encryption support.

Assign_And_Protect_Memory_Block

Makes this stream view a region of SourceMS memory without copying it. The view does not own that memory.
function ThMemoryStream.Assign_And_Protect_Memory_Block(SourceMS: ThMemoryStream; FromPosition, BlockSize: NativeUInt): Boolean;

Parameters

  • SourceMS: ThMemoryStream.
  • FromPosition, BlockSize: NativeUInt.

Return Value

Returns Boolean.
BlockSize must be at least 10 bytes and the range must fit SourceMS. Keep SourceMS alive and unchanged while the view is used.

Reduce_Spare_Allocation

Shrinks allocated capacity to the current Size and resets Position to zero.
procedure ThMemoryStream.Reduce_Spare_Allocation;
This method requires a nonempty, unprotected stream. Check Last_Allocation_Had_Errors after calling it.

Read

Reads bytes from internal memory pointer and advances cursor.
function ThMemoryStream.Read(var Buffer; Count: Cardinal): Cardinal; override;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Cardinal.

Return Value

Returns the number of bytes transferred; check it against Count.

Write

Writes bytes to internal memory pointer; auto-grows capacity when needed.
function ThMemoryStream.Write(const Buffer; Count: Cardinal): Cardinal; override;

Parameters

  • Buffer: untyped memory buffer.
  • Count: Cardinal.

Return Value

Returns the number of bytes transferred; check it against Count.

Load_From_File

Clears this stream and copies a file into it. CopyFromEnd selects a tail section when it is between 1 and file size minus 2.
function ThMemoryStream.Load_From_File(FileName: String; CopyFromEnd: Int64 = 0): Boolean;

Parameters

  • FileName: String.
  • CopyFromEnd: Int64 = 0.

Return Value

Returns True when the requested bytes were copied. The position is reset to zero after the attempt.

Save_To_File

Saves current buffer to file and optionally clears stream after successful save.
function ThMemoryStream.Save_To_File(FileName: String; Reset_After_Save: Boolean = False): Boolean;

Parameters

  • FileName: String.
  • Reset_After_Save: Boolean = False.

Return Value

Returns Boolean.

CopyFrom_MS

Copies bytes directly from another memory stream and advances its Position.
function ThMemoryStream.CopyFrom_MS(Source: ThMemoryStream; Count: Int64): Int64;

Parameters

  • Source: ThMemoryStream.
  • Count: Int64; a nonpositive value copies the whole source from byte zero.

Return Value

Returns the number of bytes copied.
For very large transfers, this implementation performs one direct write. Check the returned byte count.

Read_WideText

Memory-stream override for wide text reading.
function ThMemoryStream.Read_WideText(ReadLength: Cardinal): String; override;

Parameters

  • ReadLength: Cardinal.

Return Value

Returns String.
The memory override reads the requested bytes first, then shortens the returned string at a null code unit.

Write_WideText

Writes UTF-16 code units directly to memory, resizing the buffer if needed.
WriteLength counts code units; zero uses Length(Value). A shorter value is padded, and a longer value is truncated.
function ThMemoryStream.Write_WideText(const Value: String; WriteLength: Cardinal = 0; Fill: Byte = 0): Boolean; override;

Parameters

  • Value: String.
  • WriteLength: Cardinal = 0.
  • Fill: Byte = 0.

Return Value

Returns Boolean.
For nonzero Fill, this override fills both bytes of each padding code unit with Fill; the ThStream implementation writes Fill as a Word value.

Read_AnsiText

Memory-stream override for ANSI text reading.
function ThMemoryStream.Read_AnsiText(ReadLength: Cardinal): RawByteString; override;

Parameters

  • ReadLength: Cardinal.

Return Value

Returns RawByteString.
The memory override reads the requested bytes first, then shortens the returned string at a null byte.

Write_AnsiText

Memory-stream override for ANSI text writing.
function ThMemoryStream.Write_AnsiText(const Value: RawByteString; WriteLength: Cardinal = 0; Fill: Byte = 0): Boolean; override;

Parameters

  • Value: RawByteString.
  • WriteLength: Cardinal = 0.
  • Fill: Byte = 0.

Return Value

Returns Boolean.

Replace_AnsiString

Replaces all matching ANSI byte sequences in the selected range and resets Position to zero.
function ThMemoryStream.Replace_AnsiString(FindString, Replaceto: RawByteString; FromPos: Int64 = 0; ToPos: Int64 = 0; CaseSensitive: Boolean = False): Boolean;

Parameters

  • FindString, Replaceto: RawByteString.
  • FromPos: Int64 = 0.
  • ToPos: Int64 = 0.
  • CaseSensitive: Boolean = False.

Return Value

Returns True when at least one match was found and replaced.

Read_From_Socket

Waits for readable socket data, then appends up to Read_Bytes_Limitation bytes at the current Position.
function ThMemoryStream.Read_From_Socket(var _Socket: NativeUInt; const TimeOut: Double; Read_Bytes_Limitation: Word = 0): Boolean;

Parameters

  • _Socket: NativeUInt.
  • TimeOut: Double.
  • Read_Bytes_Limitation: Word = 0.

Return Value

Returns Boolean.
The limit defaults to 32768 bytes when zero or outside 1..32768. True means at least one byte was received.

Write_8KB_Packet_To_Socket

Sends up to 8192 bytes from the current Position and advances Position by the bytes sent.
function ThMemoryStream.Write_8KB_Packet_To_Socket(var _Socket: NativeUInt): Boolean;

Parameters

  • _Socket: NativeUInt.

Return Value

Returns True only if the requested chunk was sent in full; a partial send still advances Position.

Write_Everything_To_Socket

Sends the entire buffer starting at byte zero; it does not use or advance Position.
function ThMemoryStream.Write_Everything_To_Socket(var _Socket: NativeUInt; Clear_Buffer_IF_Sent: Boolean = False): Boolean;

Parameters

  • _Socket: NativeUInt.
  • Clear_Buffer_IF_Sent: Boolean = False.

Return Value

Returns True only if all bytes were sent in one call.
Clear_Buffer_IF_Sent clears the stream only after a complete send. Use Write_8KB_Packet_To_Socket for incremental sends.

Encode_SYE_Sapphire

Encrypts stream content with SYE Sapphire using a byte-array private key.
function ThMemoryStream.Encode_SYE_Sapphire(const Private_Key: array of Byte): Boolean;

Parameters

  • Private_Key: array of Byte.

Return Value

Returns Boolean.

Decode_SYE_Sapphire

Decrypts SYE Sapphire content using the same private key material.
function ThMemoryStream.Decode_SYE_Sapphire(const Private_Key: array of Byte): Boolean;

Parameters

  • Private_Key: array of Byte.

Return Value

Returns Boolean.

Encode_OLD_Sapphire (Win32)

Legacy Sapphire encoder (string-key variant), available on Win32 only.
function ThMemoryStream.Encode_OLD_Sapphire(const Sapphire_Key: String): Boolean;

Parameters

  • Sapphire_Key: String.

Return Value

Returns Boolean.

Decode_OLD_Sapphire (Win32)

Legacy Sapphire decoder (string-key variant), available on Win32 only.
function ThMemoryStream.Decode_OLD_Sapphire(const Sapphire_Key: String): Boolean;

Parameters

  • Sapphire_Key: String.

Return Value

Returns Boolean.

Compress

Compresses the buffer with zlib and adds an eight-byte private footer containing original size and signature.
function ThMemoryStream.Compress(Level: Byte = 4): Boolean;

Parameters

  • Level: Byte = 4.

Return Value

Returns True when compression succeeds; the original buffer remains intact on failure.
Level is clamped to 2..9; compression requires at least eight input bytes and an unprotected stream.

Example

var
  MS: ThMemoryStream;
begin
  MS := ThMemoryStream.Create;
  try
    MS.Write_AnsiText('Example data to compress');
    if MS.Compress then
      if not MS.DeCompress then
        Write_Log_File('Decompression failed');
  finally
    MS.Free;
  end;
end;

DeCompress

Decompresses the unit's zlib plus private-footer format and resets Position to zero on success.
function ThMemoryStream.DeCompress: Boolean;

Return Value

Returns True when the footer and decompressed size are valid.
The private footer is required. Generic zlib data cannot be passed directly to this method.

Properties

Memory-stream specific exposed internals and allocation diagnostics.

property ThMemoryStream.Memory: Pointer read _Memory_Ptr;
property ThMemoryStream.Last_Allocation_Had_Errors: Boolean read _Last_Allocation_Had_Errors;

Property Details

  • ThMemoryStream.Memory: pointer to current internal buffer; may change after writes/realloc/compress/decompress.
  • ThMemoryStream.Last_Allocation_Had_Errors: indicates latest allocation/reallocation failure or protected-block restriction hit.

Related Restrictions

  • Assign_And_Protect_Memory_Block sets protected mode; resizing and many mutating operations are blocked.
  • SetSize uses growth tiers (512KB, 1MB, 8MB, 20MB, then 40MB steps) and includes Win32 safety limit around 1.8GB.

Create_Package_File

Creates an HStreams package from existing files listed in a CRLF-separated string. This is a proprietary archive format with individually compressed contents and a file index; it is not a standard ZIP file.
function Create_Package_File(ZipFileName, Source_Files_List: String): Boolean;
The package stores each file's base name, not its source directory. The format uses 32-bit file positions and sizes, so keep packages below 2 GB. Files missing from the list are skipped. An existing destination file is replaced.
Returns True when at least one file was packed successfully.

Example

if not Create_Package_File('C:\Data\backup.pkg',
  'C:\Data\a.txt' + #13#10 + 'C:\Data\b.txt') then
  Write_Log_File('Package creation failed');

Get_Files_List

Reads the names stored in an HStreams package and returns them as CRLF-separated text.
function Get_Files_List(ZipFileName: String): String;
Returns an empty string if the package cannot be opened or its footer signature is invalid.

Extract_File_Into_MS

Finds a named entry in an HStreams package, decompresses it and loads it into MS.
function Extract_File_Into_MS(FileName, ZipFileName: String;
  MS: ThMemoryStream): Boolean;
The file name comparison uses the framework's case-insensitive string comparison. The caller creates and owns MS.
Returns True when the entry was found and decompressed.

Extract_All_Files

Extracts every entry of an HStreams package into ExtractTo. The stored names are flattened base names, so source directory paths are not restored.
function Extract_All_Files(ZipFileName, ExtractTo: String): Boolean;
The routine creates the destination directory if needed. Check extracted files when a write failure matters: the current implementation does not include Save_To_File results in its Boolean result.

Fast_File_CRC_Word

Opens a file and calculates its fast 16-bit XOR checksum with ThStream.Calc_CRC_Word.
function Fast_File_CRC_Word(FileName: String): Word;
Returns 65535 if the file could not be opened. This value can also be a valid checksum, so it is not an unambiguous error code.

Decode_Quoted_Printable

Decodes a range of quoted-printable bytes. Target is an output parameter: the function creates a new memory stream and assigns it to Target.
function Decode_Quoted_Printable(Source: ThMemoryStream;
  FromPos, UntilPos: Cardinal; var Target: ThMemoryStream): Boolean;
The range uses byte offsets and includes UntilPos; zero means the last byte. On success, free Target after use. On failure, Target is nil.

Write_Log_File_From_Stream

Appends the whole source stream to the framework log, then appends CRLF. With ExtCRLF = True, it appends three CRLF pairs instead. Copying starts at byte zero and changes the source stream's position.
procedure Write_Log_File_From_Stream(Source: ThStream;
  ExtCRLF: Boolean = False);
An empty or nil source produces no output.

Encode_BASE64_String

Encodes all bytes of a RawByteString as Base64 text.
function Encode_BASE64_String(Input: RawByteString): RawByteString;

Parameters

  • Input: RawByteString.

Return Value

Returns RawByteString.

Decode_BASE64_String

Decodes Base64 text to binary RawByteString. The decoder skips characters outside its Base64 alphabet.
function Decode_BASE64_String(Input: RawByteString): RawByteString;

Parameters

  • Input: RawByteString.

Return Value

Returns RawByteString.

Encode_BASE64

Encodes all bytes of Input into Output, replacing the previous Output content and resetting Output.Position.
procedure Encode_BASE64(Input, Output: ThMemoryStream);

Parameters

  • Input, Output: ThMemoryStream.

Decode_BASE64

Decodes an inclusive Base64 byte range from Source into Target, replacing the previous Target content.
procedure Decode_BASE64(Source, Target: ThMemoryStream; FromPos, UntilPos: NativeUInt);

Parameters

  • Source, Target: ThMemoryStream.
  • FromPos, UntilPos: NativeUInt.

Generate_Sapphire_Key_Array_For_Delphi

Generates Delphi-ready byte-array literal text for Sapphire keys.
function Generate_Sapphire_Key_Array_For_Delphi(KeyLen: Integer): String;

Parameters

  • KeyLen: Integer.

Return Value

Returns String.

Test_Does_String_Contain_Only_BASE64_Chars

Checks whether a nonempty string contains only Base64 alphabet characters, padding characters (=) and CR/LF line breaks.
function Test_Does_String_Contain_Only_BASE64_Chars(
  const Input: String): Boolean;
This is a character-set check. It does not verify padding position, block length or whether decoding succeeds.