unit Chilkat.Stream;

{
  Pascal wrapper for Chilkat Stream.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TStream wraps CkStream via the C bridge layer. }
  TStream = class(TChilkatBase)
  private
    FOnAbortCheck: TChilkatAbortCheckEvent;
    FOnPercentDone: TChilkatPercentDoneEvent;
    FOnProgressInfo: TChilkatProgressInfoEvent;
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetAbortCurrent: Boolean;
    procedure SetAbortCurrent(AValue: Boolean);
    function  GetCanRead: Boolean;
    function  GetCanWrite: Boolean;
    function  GetDataAvailable: Boolean;
    function  GetDefaultChunkSize: Integer;
    procedure SetDefaultChunkSize(AValue: Integer);
    function  GetEndOfStream: Boolean;
    function  GetIsWriteClosed: Boolean;
    function  GetLength: Int64;
    procedure SetLength(AValue: Int64);
    function  GetLength32: Integer;
    procedure SetLength32(AValue: Integer);
    function  GetNumReceived: Int64;
    function  GetNumSent: Int64;
    function  GetReadFailReason: Integer;
    function  GetReadTimeoutMs: Integer;
    procedure SetReadTimeoutMs(AValue: Integer);
    function  GetSinkFile: string;
    procedure SetSinkFile(AValue: string);
    function  GetSourceFile: string;
    procedure SetSourceFile(AValue: string);
    function  GetStringBom: Boolean;
    procedure SetStringBom(AValue: Boolean);
    function  GetStringCharset: string;
    procedure SetStringCharset(AValue: string);
    function  GetWriteFailReason: Integer;
    function  GetWriteTimeoutMs: Integer;
    procedure SetWriteTimeoutMs(AValue: Integer);
    function  GetSourceFilePart: Integer;
    procedure SetSourceFilePart(AValue: Integer);
    function  GetSourceFilePartSize: Integer;
    procedure SetSourceFilePartSize(AValue: Integer);
    function  GetSinkFileAppend: Boolean;
    procedure SetSinkFileAppend(AValue: Boolean);
    function  GetHeartbeatMs: Integer;
    procedure SetHeartbeatMs(AValue: Integer);
    procedure SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
    procedure SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
    procedure SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property AbortCurrent: Boolean read GetAbortCurrent write SetAbortCurrent;
    property CanRead: Boolean read GetCanRead;
    property CanWrite: Boolean read GetCanWrite;
    property DataAvailable: Boolean read GetDataAvailable;
    property DefaultChunkSize: Integer read GetDefaultChunkSize write SetDefaultChunkSize;
    property EndOfStream: Boolean read GetEndOfStream;
    property IsWriteClosed: Boolean read GetIsWriteClosed;
    property Length: Int64 read GetLength write SetLength;
    property Length32: Integer read GetLength32 write SetLength32;
    property NumReceived: Int64 read GetNumReceived;
    property NumSent: Int64 read GetNumSent;
    property ReadFailReason: Integer read GetReadFailReason;
    property ReadTimeoutMs: Integer read GetReadTimeoutMs write SetReadTimeoutMs;
    property SinkFile: string read GetSinkFile write SetSinkFile;
    property SourceFile: string read GetSourceFile write SetSourceFile;
    property StringBom: Boolean read GetStringBom write SetStringBom;
    property StringCharset: string read GetStringCharset write SetStringCharset;
    property WriteFailReason: Integer read GetWriteFailReason;
    property WriteTimeoutMs: Integer read GetWriteTimeoutMs write SetWriteTimeoutMs;
    property SourceFilePart: Integer read GetSourceFilePart write SetSourceFilePart;
    property SourceFilePartSize: Integer read GetSourceFilePartSize write SetSourceFilePartSize;
    property SinkFileAppend: Boolean read GetSinkFileAppend write SetSinkFileAppend;
    property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;

    { Event callbacks.  Return True from OnAbortCheck / OnPercentDone
      to abort the running method.  Callbacks are invoked on the
      thread that called the Chilkat method.  The HeartbeatMs
      property controls the AbortCheck frequency. }
    property OnAbortCheck: TChilkatAbortCheckEvent read FOnAbortCheck write SetOnAbortCheck;
    property OnPercentDone: TChilkatPercentDoneEvent read FOnPercentDone write SetOnPercentDone;
    property OnProgressInfo: TChilkatProgressInfoEvent read FOnProgressInfo write SetOnProgressInfo;

    function  ReadBytesENC(const encoding: string): string;
    function  ReadNBytesENC(numBytes: Integer; const encoding: string): string;
    function  ReadString: string;
    function  ReadToCRLF: string;
    function  ReadUntilMatch(const matchStr: string): string;
    procedure Reset;
    function  SetSourceString(const srcStr: string; const charset: string): Boolean;
    function  WriteByte(byteVal: Integer): Boolean;
    function  WriteBytesENC(const byteData: string; const encoding: string): Boolean;
    function  WriteClose: Boolean;
    function  WriteString(const str: string): Boolean;
    function  ReadBd(binData: TChilkatBase): Boolean;
    function  ReadSb(sb: TChilkatBase): Boolean;
    function  WriteBd(binData: TChilkatBase): Boolean;
    function  WriteSb(sb: TChilkatBase): Boolean;
    function  WriteBytes2(pByteData: Pointer; szByteData: LongWord): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkStream_Create  = function(): Pointer; cdecl;
  TCkStream_Dispose = procedure(handle: Pointer); cdecl;
  TCkBridgeAbortCheckCb   = function(userData: Pointer): Integer; cdecl;
  TCkBridgePercentDoneCb  = function(pctDone: Integer; userData: Pointer): Integer; cdecl;
  TCkBridgeProgressInfoCb = procedure(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
  TCkStream_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkStream_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkStream_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkStream_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkStream_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkStream_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkStream_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkStream_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkStream_get_AbortCurrent = function(handle: Pointer): LongBool; cdecl;
  TCkStream_put_AbortCurrent = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkStream_get_CanRead = function(handle: Pointer): LongBool; cdecl;
  TCkStream_get_CanWrite = function(handle: Pointer): LongBool; cdecl;
  TCkStream_get_DataAvailable = function(handle: Pointer): LongBool; cdecl;
  TCkStream_get_DefaultChunkSize = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_DefaultChunkSize = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_get_EndOfStream = function(handle: Pointer): LongBool; cdecl;
  TCkStream_get_IsWriteClosed = function(handle: Pointer): LongBool; cdecl;
  TCkStream_get_Length = function(handle: Pointer): Int64; cdecl;
  TCkStream_put_Length = procedure(handle: Pointer; value: Int64); cdecl;
  TCkStream_get_Length32 = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_Length32 = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_get_NumReceived = function(handle: Pointer): Int64; cdecl;
  TCkStream_get_NumSent = function(handle: Pointer): Int64; cdecl;
  TCkStream_get_ReadFailReason = function(handle: Pointer): Integer; cdecl;
  TCkStream_get_ReadTimeoutMs = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_ReadTimeoutMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_get_SinkFile = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_put_SinkFile = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkStream_get_SourceFile = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_put_SourceFile = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkStream_get_StringBom = function(handle: Pointer): LongBool; cdecl;
  TCkStream_put_StringBom = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkStream_get_StringCharset = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_put_StringCharset = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkStream_get_WriteFailReason = function(handle: Pointer): Integer; cdecl;
  TCkStream_get_WriteTimeoutMs = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_WriteTimeoutMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_get_SourceFilePart = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_SourceFilePart = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_get_SourceFilePartSize = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_SourceFilePartSize = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_get_SinkFileAppend = function(handle: Pointer): LongBool; cdecl;
  TCkStream_put_SinkFileAppend = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkStream_get_HeartbeatMs = function(handle: Pointer): Integer; cdecl;
  TCkStream_put_HeartbeatMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkStream_ReadBytesENC = function(handle: Pointer; encoding: PAnsiChar): PAnsiChar; cdecl;
  TCkStream_ReadNBytesENC = function(handle: Pointer; numBytes: Integer; encoding: PAnsiChar): PAnsiChar; cdecl;
  TCkStream_ReadString = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_ReadToCRLF = function(handle: Pointer): PAnsiChar; cdecl;
  TCkStream_ReadUntilMatch = function(handle: Pointer; matchStr: PAnsiChar): PAnsiChar; cdecl;
  TCkStream_Reset = procedure(handle: Pointer); cdecl;
  TCkStream_SetSourceString = function(handle: Pointer; srcStr: PAnsiChar; charset: PAnsiChar): LongBool; cdecl;
  TCkStream_WriteByte = function(handle: Pointer; byteVal: Integer): LongBool; cdecl;
  TCkStream_WriteBytesENC = function(handle: Pointer; byteData: PAnsiChar; encoding: PAnsiChar): LongBool; cdecl;
  TCkStream_WriteClose = function(handle: Pointer): LongBool; cdecl;
  TCkStream_WriteString = function(handle: Pointer; str: PAnsiChar): LongBool; cdecl;
  TCkStream_ReadBd = function(handle: Pointer; binData: Pointer): LongBool; cdecl;
  TCkStream_ReadSb = function(handle: Pointer; sb: Pointer): LongBool; cdecl;
  TCkStream_WriteBd = function(handle: Pointer; binData: Pointer): LongBool; cdecl;
  TCkStream_WriteSb = function(handle: Pointer; sb: Pointer): LongBool; cdecl;
  TCkStream_WriteBytes2 = function(handle: Pointer; pByteData: Pointer; szByteData: LongWord): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkStream_Create:  TCkStream_Create  = nil;
  CkStream_Dispose: TCkStream_Dispose = nil;
  CkStream_SetAbortCheckCallback:   TCkStream_SetAbortCheckCallback   = nil;
  CkStream_SetPercentDoneCallback:  TCkStream_SetPercentDoneCallback  = nil;
  CkStream_SetProgressInfoCallback: TCkStream_SetProgressInfoCallback = nil;
  CkStream_get_LastErrorHtml: TCkStream_get_LastErrorHtml = nil;
  CkStream_get_LastErrorText: TCkStream_get_LastErrorText = nil;
  CkStream_get_LastErrorXml: TCkStream_get_LastErrorXml = nil;
  CkStream_get_Version: TCkStream_get_Version = nil;
  CkStream_get_DebugLogFilePath: TCkStream_get_DebugLogFilePath = nil;
  CkStream_put_DebugLogFilePath: TCkStream_put_DebugLogFilePath = nil;
  CkStream_get_VerboseLogging: TCkStream_get_VerboseLogging = nil;
  CkStream_put_VerboseLogging: TCkStream_put_VerboseLogging = nil;
  CkStream_get_LastMethodSuccess: TCkStream_get_LastMethodSuccess = nil;
  CkStream_put_LastMethodSuccess: TCkStream_put_LastMethodSuccess = nil;
  CkStream_get_AbortCurrent: TCkStream_get_AbortCurrent = nil;
  CkStream_put_AbortCurrent: TCkStream_put_AbortCurrent = nil;
  CkStream_get_CanRead: TCkStream_get_CanRead = nil;
  CkStream_get_CanWrite: TCkStream_get_CanWrite = nil;
  CkStream_get_DataAvailable: TCkStream_get_DataAvailable = nil;
  CkStream_get_DefaultChunkSize: TCkStream_get_DefaultChunkSize = nil;
  CkStream_put_DefaultChunkSize: TCkStream_put_DefaultChunkSize = nil;
  CkStream_get_EndOfStream: TCkStream_get_EndOfStream = nil;
  CkStream_get_IsWriteClosed: TCkStream_get_IsWriteClosed = nil;
  CkStream_get_Length: TCkStream_get_Length = nil;
  CkStream_put_Length: TCkStream_put_Length = nil;
  CkStream_get_Length32: TCkStream_get_Length32 = nil;
  CkStream_put_Length32: TCkStream_put_Length32 = nil;
  CkStream_get_NumReceived: TCkStream_get_NumReceived = nil;
  CkStream_get_NumSent: TCkStream_get_NumSent = nil;
  CkStream_get_ReadFailReason: TCkStream_get_ReadFailReason = nil;
  CkStream_get_ReadTimeoutMs: TCkStream_get_ReadTimeoutMs = nil;
  CkStream_put_ReadTimeoutMs: TCkStream_put_ReadTimeoutMs = nil;
  CkStream_get_SinkFile: TCkStream_get_SinkFile = nil;
  CkStream_put_SinkFile: TCkStream_put_SinkFile = nil;
  CkStream_get_SourceFile: TCkStream_get_SourceFile = nil;
  CkStream_put_SourceFile: TCkStream_put_SourceFile = nil;
  CkStream_get_StringBom: TCkStream_get_StringBom = nil;
  CkStream_put_StringBom: TCkStream_put_StringBom = nil;
  CkStream_get_StringCharset: TCkStream_get_StringCharset = nil;
  CkStream_put_StringCharset: TCkStream_put_StringCharset = nil;
  CkStream_get_WriteFailReason: TCkStream_get_WriteFailReason = nil;
  CkStream_get_WriteTimeoutMs: TCkStream_get_WriteTimeoutMs = nil;
  CkStream_put_WriteTimeoutMs: TCkStream_put_WriteTimeoutMs = nil;
  CkStream_get_SourceFilePart: TCkStream_get_SourceFilePart = nil;
  CkStream_put_SourceFilePart: TCkStream_put_SourceFilePart = nil;
  CkStream_get_SourceFilePartSize: TCkStream_get_SourceFilePartSize = nil;
  CkStream_put_SourceFilePartSize: TCkStream_put_SourceFilePartSize = nil;
  CkStream_get_SinkFileAppend: TCkStream_get_SinkFileAppend = nil;
  CkStream_put_SinkFileAppend: TCkStream_put_SinkFileAppend = nil;
  CkStream_get_HeartbeatMs: TCkStream_get_HeartbeatMs = nil;
  CkStream_put_HeartbeatMs: TCkStream_put_HeartbeatMs = nil;
  CkStream_ReadBytesENC: TCkStream_ReadBytesENC = nil;
  CkStream_ReadNBytesENC: TCkStream_ReadNBytesENC = nil;
  CkStream_ReadString: TCkStream_ReadString = nil;
  CkStream_ReadToCRLF: TCkStream_ReadToCRLF = nil;
  CkStream_ReadUntilMatch: TCkStream_ReadUntilMatch = nil;
  CkStream_Reset: TCkStream_Reset = nil;
  CkStream_SetSourceString: TCkStream_SetSourceString = nil;
  CkStream_WriteByte: TCkStream_WriteByte = nil;
  CkStream_WriteBytesENC: TCkStream_WriteBytesENC = nil;
  CkStream_WriteClose: TCkStream_WriteClose = nil;
  CkStream_WriteString: TCkStream_WriteString = nil;
  CkStream_ReadBd: TCkStream_ReadBd = nil;
  CkStream_ReadSb: TCkStream_ReadSb = nil;
  CkStream_WriteBd: TCkStream_WriteBd = nil;
  CkStream_WriteSb: TCkStream_WriteSb = nil;
  CkStream_WriteBytes2: TCkStream_WriteBytes2 = nil;

constructor TStream.Create;
begin
  inherited Create;
  FHandle := CkStream_Create();
end;

destructor TStream.Destroy;
begin
  if FHandle <> nil then
    CkStream_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

{ ---- Event callback thunks ---- }
{ Standalone cdecl functions registered with the C bridge.  The bridge
  passes back the userData pointer, which carries the Pascal object
  instance.  A non-zero return value aborts the running method. }

function TStream_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TStream;
begin
  Result := 0;
  obj := TStream(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

function TStream_PercentDoneThunk(pctDone: Integer; userData: Pointer): Integer; cdecl;
var
  obj: TStream;
begin
  Result := 0;
  obj := TStream(userData);
  if Assigned(obj) and Assigned(obj.FOnPercentDone) then
    if obj.FOnPercentDone(obj, pctDone) then Result := 1;
end;

procedure TStream_ProgressInfoThunk(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
var
  obj: TStream;
begin
  obj := TStream(userData);
  if Assigned(obj) and Assigned(obj.FOnProgressInfo) then
    obj.FOnProgressInfo(obj, CkToStr(name), CkToStr(value));
end;

procedure TStream.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkStream_SetAbortCheckCallback(FHandle, @TStream_AbortCheckThunk, Self)
  else
    CkStream_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TStream.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkStream_SetPercentDoneCallback(FHandle, @TStream_PercentDoneThunk, Self)
  else
    CkStream_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TStream.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkStream_SetProgressInfoCallback(FHandle, @TStream_ProgressInfoThunk, Self)
  else
    CkStream_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TStream.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkStream_get_LastErrorHtml(FHandle));
end;

function TStream.GetLastErrorText: string;
begin
  Result := CkToStr(CkStream_get_LastErrorText(FHandle));
end;

function TStream.GetLastErrorXml: string;
begin
  Result := CkToStr(CkStream_get_LastErrorXml(FHandle));
end;

function TStream.GetVersion: string;
begin
  Result := CkToStr(CkStream_get_Version(FHandle));
end;

function TStream.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkStream_get_DebugLogFilePath(FHandle));
end;

procedure TStream.SetDebugLogFilePath(AValue: string);
begin
  CkStream_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TStream.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkStream_get_VerboseLogging(FHandle));
end;

procedure TStream.SetVerboseLogging(AValue: Boolean);
begin
  CkStream_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TStream.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkStream_get_LastMethodSuccess(FHandle));
end;

procedure TStream.SetLastMethodSuccess(AValue: Boolean);
begin
  CkStream_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TStream.GetAbortCurrent: Boolean;
begin
  Result := Boolean(CkStream_get_AbortCurrent(FHandle));
end;

procedure TStream.SetAbortCurrent(AValue: Boolean);
begin
  CkStream_put_AbortCurrent(FHandle, LongBool(AValue));
end;

function TStream.GetCanRead: Boolean;
begin
  Result := Boolean(CkStream_get_CanRead(FHandle));
end;

function TStream.GetCanWrite: Boolean;
begin
  Result := Boolean(CkStream_get_CanWrite(FHandle));
end;

function TStream.GetDataAvailable: Boolean;
begin
  Result := Boolean(CkStream_get_DataAvailable(FHandle));
end;

function TStream.GetDefaultChunkSize: Integer;
begin
  Result := CkStream_get_DefaultChunkSize(FHandle);
end;

procedure TStream.SetDefaultChunkSize(AValue: Integer);
begin
  CkStream_put_DefaultChunkSize(FHandle, AValue);
end;

function TStream.GetEndOfStream: Boolean;
begin
  Result := Boolean(CkStream_get_EndOfStream(FHandle));
end;

function TStream.GetIsWriteClosed: Boolean;
begin
  Result := Boolean(CkStream_get_IsWriteClosed(FHandle));
end;

function TStream.GetLength: Int64;
begin
  Result := CkStream_get_Length(FHandle);
end;

procedure TStream.SetLength(AValue: Int64);
begin
  CkStream_put_Length(FHandle, AValue);
end;

function TStream.GetLength32: Integer;
begin
  Result := CkStream_get_Length32(FHandle);
end;

procedure TStream.SetLength32(AValue: Integer);
begin
  CkStream_put_Length32(FHandle, AValue);
end;

function TStream.GetNumReceived: Int64;
begin
  Result := CkStream_get_NumReceived(FHandle);
end;

function TStream.GetNumSent: Int64;
begin
  Result := CkStream_get_NumSent(FHandle);
end;

function TStream.GetReadFailReason: Integer;
begin
  Result := CkStream_get_ReadFailReason(FHandle);
end;

function TStream.GetReadTimeoutMs: Integer;
begin
  Result := CkStream_get_ReadTimeoutMs(FHandle);
end;

procedure TStream.SetReadTimeoutMs(AValue: Integer);
begin
  CkStream_put_ReadTimeoutMs(FHandle, AValue);
end;

function TStream.GetSinkFile: string;
begin
  Result := CkToStr(CkStream_get_SinkFile(FHandle));
end;

procedure TStream.SetSinkFile(AValue: string);
begin
  CkStream_put_SinkFile(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TStream.GetSourceFile: string;
begin
  Result := CkToStr(CkStream_get_SourceFile(FHandle));
end;

procedure TStream.SetSourceFile(AValue: string);
begin
  CkStream_put_SourceFile(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TStream.GetStringBom: Boolean;
begin
  Result := Boolean(CkStream_get_StringBom(FHandle));
end;

procedure TStream.SetStringBom(AValue: Boolean);
begin
  CkStream_put_StringBom(FHandle, LongBool(AValue));
end;

function TStream.GetStringCharset: string;
begin
  Result := CkToStr(CkStream_get_StringCharset(FHandle));
end;

procedure TStream.SetStringCharset(AValue: string);
begin
  CkStream_put_StringCharset(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TStream.GetWriteFailReason: Integer;
begin
  Result := CkStream_get_WriteFailReason(FHandle);
end;

function TStream.GetWriteTimeoutMs: Integer;
begin
  Result := CkStream_get_WriteTimeoutMs(FHandle);
end;

procedure TStream.SetWriteTimeoutMs(AValue: Integer);
begin
  CkStream_put_WriteTimeoutMs(FHandle, AValue);
end;

function TStream.GetSourceFilePart: Integer;
begin
  Result := CkStream_get_SourceFilePart(FHandle);
end;

procedure TStream.SetSourceFilePart(AValue: Integer);
begin
  CkStream_put_SourceFilePart(FHandle, AValue);
end;

function TStream.GetSourceFilePartSize: Integer;
begin
  Result := CkStream_get_SourceFilePartSize(FHandle);
end;

procedure TStream.SetSourceFilePartSize(AValue: Integer);
begin
  CkStream_put_SourceFilePartSize(FHandle, AValue);
end;

function TStream.GetSinkFileAppend: Boolean;
begin
  Result := Boolean(CkStream_get_SinkFileAppend(FHandle));
end;

procedure TStream.SetSinkFileAppend(AValue: Boolean);
begin
  CkStream_put_SinkFileAppend(FHandle, LongBool(AValue));
end;

function TStream.GetHeartbeatMs: Integer;
begin
  Result := CkStream_get_HeartbeatMs(FHandle);
end;

procedure TStream.SetHeartbeatMs(AValue: Integer);
begin
  CkStream_put_HeartbeatMs(FHandle, AValue);
end;

function TStream.ReadBytesENC(const encoding: string): string;
begin
  Result := CkToStr(CkStream_ReadBytesENC(FHandle, PAnsiChar(StrToCk(encoding))));
end;

function TStream.ReadNBytesENC(numBytes: Integer; const encoding: string): string;
begin
  Result := CkToStr(CkStream_ReadNBytesENC(FHandle, numBytes, PAnsiChar(StrToCk(encoding))));
end;

function TStream.ReadString: string;
begin
  Result := CkToStr(CkStream_ReadString(FHandle));
end;

function TStream.ReadToCRLF: string;
begin
  Result := CkToStr(CkStream_ReadToCRLF(FHandle));
end;

function TStream.ReadUntilMatch(const matchStr: string): string;
begin
  Result := CkToStr(CkStream_ReadUntilMatch(FHandle, PAnsiChar(StrToCk(matchStr))));
end;

procedure TStream.Reset;
begin
  CkStream_Reset(FHandle);
end;

function TStream.SetSourceString(const srcStr: string; const charset: string): Boolean;
begin
  Result := Boolean(CkStream_SetSourceString(FHandle, PAnsiChar(StrToCk(srcStr)), PAnsiChar(StrToCk(charset))));
end;

function TStream.WriteByte(byteVal: Integer): Boolean;
begin
  Result := Boolean(CkStream_WriteByte(FHandle, byteVal));
end;

function TStream.WriteBytesENC(const byteData: string; const encoding: string): Boolean;
begin
  Result := Boolean(CkStream_WriteBytesENC(FHandle, PAnsiChar(StrToCk(byteData)), PAnsiChar(StrToCk(encoding))));
end;

function TStream.WriteClose: Boolean;
begin
  Result := Boolean(CkStream_WriteClose(FHandle));
end;

function TStream.WriteString(const str: string): Boolean;
begin
  Result := Boolean(CkStream_WriteString(FHandle, PAnsiChar(StrToCk(str))));
end;

function TStream.ReadBd(binData: TChilkatBase): Boolean;
begin
  Result := Boolean(CkStream_ReadBd(FHandle, binData.Handle));
end;

function TStream.ReadSb(sb: TChilkatBase): Boolean;
begin
  Result := Boolean(CkStream_ReadSb(FHandle, sb.Handle));
end;

function TStream.WriteBd(binData: TChilkatBase): Boolean;
begin
  Result := Boolean(CkStream_WriteBd(FHandle, binData.Handle));
end;

function TStream.WriteSb(sb: TChilkatBase): Boolean;
begin
  Result := Boolean(CkStream_WriteSb(FHandle, sb.Handle));
end;

function TStream.WriteBytes2(pByteData: Pointer; szByteData: LongWord): Boolean;
begin
  Result := Boolean(CkStream_WriteBytes2(FHandle, pByteData, szByteData));
end;

initialization
  Chilkat_GetProcedureAddress(CkStream_Create,  'CkStream_Create');
  Chilkat_GetProcedureAddress(CkStream_Dispose, 'CkStream_Dispose');
  Chilkat_GetProcedureAddress(CkStream_SetAbortCheckCallback, 'CkStream_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkStream_SetPercentDoneCallback, 'CkStream_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkStream_SetProgressInfoCallback, 'CkStream_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkStream_get_LastErrorHtml, 'CkStream_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkStream_get_LastErrorText, 'CkStream_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkStream_get_LastErrorXml, 'CkStream_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkStream_get_Version, 'CkStream_get_Version');
  Chilkat_GetProcedureAddress(CkStream_get_DebugLogFilePath, 'CkStream_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkStream_put_DebugLogFilePath, 'CkStream_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkStream_get_VerboseLogging, 'CkStream_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkStream_put_VerboseLogging, 'CkStream_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkStream_get_LastMethodSuccess, 'CkStream_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkStream_put_LastMethodSuccess, 'CkStream_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkStream_get_AbortCurrent, 'CkStream_get_AbortCurrent');
  Chilkat_GetProcedureAddress(CkStream_put_AbortCurrent, 'CkStream_put_AbortCurrent');
  Chilkat_GetProcedureAddress(CkStream_get_CanRead, 'CkStream_get_CanRead');
  Chilkat_GetProcedureAddress(CkStream_get_CanWrite, 'CkStream_get_CanWrite');
  Chilkat_GetProcedureAddress(CkStream_get_DataAvailable, 'CkStream_get_DataAvailable');
  Chilkat_GetProcedureAddress(CkStream_get_DefaultChunkSize, 'CkStream_get_DefaultChunkSize');
  Chilkat_GetProcedureAddress(CkStream_put_DefaultChunkSize, 'CkStream_put_DefaultChunkSize');
  Chilkat_GetProcedureAddress(CkStream_get_EndOfStream, 'CkStream_get_EndOfStream');
  Chilkat_GetProcedureAddress(CkStream_get_IsWriteClosed, 'CkStream_get_IsWriteClosed');
  Chilkat_GetProcedureAddress(CkStream_get_Length, 'CkStream_get_Length');
  Chilkat_GetProcedureAddress(CkStream_put_Length, 'CkStream_put_Length');
  Chilkat_GetProcedureAddress(CkStream_get_Length32, 'CkStream_get_Length32');
  Chilkat_GetProcedureAddress(CkStream_put_Length32, 'CkStream_put_Length32');
  Chilkat_GetProcedureAddress(CkStream_get_NumReceived, 'CkStream_get_NumReceived');
  Chilkat_GetProcedureAddress(CkStream_get_NumSent, 'CkStream_get_NumSent');
  Chilkat_GetProcedureAddress(CkStream_get_ReadFailReason, 'CkStream_get_ReadFailReason');
  Chilkat_GetProcedureAddress(CkStream_get_ReadTimeoutMs, 'CkStream_get_ReadTimeoutMs');
  Chilkat_GetProcedureAddress(CkStream_put_ReadTimeoutMs, 'CkStream_put_ReadTimeoutMs');
  Chilkat_GetProcedureAddress(CkStream_get_SinkFile, 'CkStream_get_SinkFile');
  Chilkat_GetProcedureAddress(CkStream_put_SinkFile, 'CkStream_put_SinkFile');
  Chilkat_GetProcedureAddress(CkStream_get_SourceFile, 'CkStream_get_SourceFile');
  Chilkat_GetProcedureAddress(CkStream_put_SourceFile, 'CkStream_put_SourceFile');
  Chilkat_GetProcedureAddress(CkStream_get_StringBom, 'CkStream_get_StringBom');
  Chilkat_GetProcedureAddress(CkStream_put_StringBom, 'CkStream_put_StringBom');
  Chilkat_GetProcedureAddress(CkStream_get_StringCharset, 'CkStream_get_StringCharset');
  Chilkat_GetProcedureAddress(CkStream_put_StringCharset, 'CkStream_put_StringCharset');
  Chilkat_GetProcedureAddress(CkStream_get_WriteFailReason, 'CkStream_get_WriteFailReason');
  Chilkat_GetProcedureAddress(CkStream_get_WriteTimeoutMs, 'CkStream_get_WriteTimeoutMs');
  Chilkat_GetProcedureAddress(CkStream_put_WriteTimeoutMs, 'CkStream_put_WriteTimeoutMs');
  Chilkat_GetProcedureAddress(CkStream_get_SourceFilePart, 'CkStream_get_SourceFilePart');
  Chilkat_GetProcedureAddress(CkStream_put_SourceFilePart, 'CkStream_put_SourceFilePart');
  Chilkat_GetProcedureAddress(CkStream_get_SourceFilePartSize, 'CkStream_get_SourceFilePartSize');
  Chilkat_GetProcedureAddress(CkStream_put_SourceFilePartSize, 'CkStream_put_SourceFilePartSize');
  Chilkat_GetProcedureAddress(CkStream_get_SinkFileAppend, 'CkStream_get_SinkFileAppend');
  Chilkat_GetProcedureAddress(CkStream_put_SinkFileAppend, 'CkStream_put_SinkFileAppend');
  Chilkat_GetProcedureAddress(CkStream_get_HeartbeatMs, 'CkStream_get_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkStream_put_HeartbeatMs, 'CkStream_put_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkStream_ReadBytesENC, 'CkStream_ReadBytesENC');
  Chilkat_GetProcedureAddress(CkStream_ReadNBytesENC, 'CkStream_ReadNBytesENC');
  Chilkat_GetProcedureAddress(CkStream_ReadString, 'CkStream_ReadString');
  Chilkat_GetProcedureAddress(CkStream_ReadToCRLF, 'CkStream_ReadToCRLF');
  Chilkat_GetProcedureAddress(CkStream_ReadUntilMatch, 'CkStream_ReadUntilMatch');
  Chilkat_GetProcedureAddress(CkStream_Reset, 'CkStream_Reset');
  Chilkat_GetProcedureAddress(CkStream_SetSourceString, 'CkStream_SetSourceString');
  Chilkat_GetProcedureAddress(CkStream_WriteByte, 'CkStream_WriteByte');
  Chilkat_GetProcedureAddress(CkStream_WriteBytesENC, 'CkStream_WriteBytesENC');
  Chilkat_GetProcedureAddress(CkStream_WriteClose, 'CkStream_WriteClose');
  Chilkat_GetProcedureAddress(CkStream_WriteString, 'CkStream_WriteString');
  Chilkat_GetProcedureAddress(CkStream_ReadBd, 'CkStream_ReadBd');
  Chilkat_GetProcedureAddress(CkStream_ReadSb, 'CkStream_ReadSb');
  Chilkat_GetProcedureAddress(CkStream_WriteBd, 'CkStream_WriteBd');
  Chilkat_GetProcedureAddress(CkStream_WriteSb, 'CkStream_WriteSb');
  Chilkat_GetProcedureAddress(CkStream_WriteBytes2, 'CkStream_WriteBytes2');

end.
