CkStream class final

Read, write, pipe, monitor, and control byte or text streams.

CkStream is a general-purpose streaming object for moving data between sources and sinks without requiring the entire payload to be handled at once. A stream can read from files, byte arrays, strings, or other sources; write to files, memory, BinData, StringBuilder, or other sinks; handle binary and text data; apply character-set rules for strings; process file parts; track bytes sent and received; and support timeouts, polling, aborts, async task integration, and end-of-stream handling.

File and memory sources

Stream from a source file, byte array, string, or selected file part without manually loading or copying all data first.

File and object sinks

Write streamed data to a sink file, append to an existing file, or output to BinData, StringBuilder, bytes, or strings.

Binary reads and writes

Read or write raw bytes, fixed byte counts, encoded byte strings, individual bytes, or BinData content.

Text streaming

Read and write strings using StringCharset, optionally use a BOM, and read text until CRLF or a matching delimiter.

Timeouts and polling

Control read and write wait behavior, poll for immediately available data, and inspect read or write failure reasons.

Progress and lifecycle

Track bytes sent and received, detect end-of-stream or write-closed state, reset streams, close writing, and abort long-running operations.

Common pattern: Configure the stream's source and sink, set the character set or chunk size if needed, then read or write using the method that matches the data type: bytes, encoded bytes, strings, BinData, or StringBuilder. Check EndOfStream, ReadFailReason, WriteFailReason, NumReceived, NumSent, and LastErrorText to understand stream progress and failures.

Timeout note: For ReadTimeoutMs, a value of 0 means a polling read, not an infinite timeout. For WriteTimeoutMs, 0 means return immediately if the stream cannot be written to right away.

A CkStream owns a native Chilkat object. It is released automatically when the Dart object is garbage collected, or immediately by dispose. Use it only from the isolate that created it.

Implemented types

Constructors

CkStream()
Creates a new CkStream object.

Properties

abortCurrent ↔ bool
When set to true, causes the currently running method to abort. Methods that always finish quickly (i.e.have no length file operations or network communications) are not affected. If no method is running, then this property is automatically reset to false when the next method is called. When the abort occurs, this property is reset to false. Both synchronous and asynchronous method calls can be aborted. (A synchronous method call could be aborted by setting this property from a separate thread.)
getter/setter pair
canRead → bool
true if the stream supports reading. Otherwise false.
no setter
canWrite → bool
true if the stream supports writing. Otherwise false.
no setter
dataAvailable → bool
true if it is known for sure that data is ready and waiting to be read. false if it is not known for sure (it may be that data is immediately available, but reading the stream with a ReadTimeoutMs of 0, which is to poll the stream, is the way to find out).
no setter
debugLogFilePath ↔ String
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
getter/setter pair
defaultChunkSize ↔ int
The default internal chunk size for reading or writing. The default value is 65536. If this property is set to 0, it will cause the default chunk size (65536) to be used. Note: The chunk size can have significant performance impact. If performance is an issue, be sure to experiment with different chunk sizes.
getter/setter pair
endOfStream → bool
true if the end-of-stream has already been reached. When the stream has already ended, all calls to Read* methods will return false with the ReadFailReason set to 3 (already at end-of-stream).
no setter
hashCode → int
The hash code for this object.
no setterinherited
heartbeatMs ↔ int
The interval in milliseconds between each AbortCheck event callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set to 0, meaning no AbortCheck event callbacks will trigger.
getter/setter pair
isDisposed → bool
Whether dispose has been called on this object.
no setter
isWriteClosed → bool
true if the stream is closed for writing. Once closed, no more data may be written to the stream.
no setter
lastErrorHtml → String
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
no setter
lastErrorText → String
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
no setter
lastErrorXml → String
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
no setter
lastMethodSuccess ↔ bool
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
getter/setter pair
length ↔ int
The length (in bytes) of the stream's source. If unknown, then this property will have a value of -1. This property may be set by the application if it knows in advance the length of the stream.
getter/setter pair
length32 ↔ int
The length (in bytes) of the stream's source. If unknown, then this property will have a value of -1. This property may be set by the application if it knows in advance the length of the stream.
getter/setter pair
numReceived → int
The number of bytes received by the stream.
no setter
numSent → int
The number of bytes sent by the stream.
no setter
onAbortCheck ↔ bool Function()?
Called periodically while a method of this object runs; return true to abort the method (it then fails with a ChilkatException).
getter/setter pair
onPercentDone ↔ bool Function(int pctDone)?
Called with the percentage completed (0-100) of the running method, when the method can measure its progress; return true to abort the method. See onAbortCheck.
getter/setter pair
onProgressInfo ↔ void Function(String name, String value)?
Called with a name/value pair describing the progress of the running method. See onAbortCheck.
getter/setter pair
readFailReason → int
This property is automatically set when a Read* method is called. It indicates the reason for failure. Possible values are:
no setter
readTimeoutMs ↔ int
The maximum number of seconds to wait while reading. The default value is 30 seconds (i.e. 30000ms). A value of 0 indicates a poll. (A polling read is to return with a timeout if no data is immediately available.)
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sinkFile ↔ String
Sets the sink to the path of a file. The file does not need to exist at the time of setting this property. The sink file will be automatically opened on demand, when the stream is first written.
getter/setter pair
sinkFileAppend ↔ bool
If true, the stream appends to the SinkFile rather than truncating and re-writing the sink file. The default value is false.
getter/setter pair
sourceFile ↔ String
Sets the source to the path of a file. The file does not need to exist at the time of setting this property. The source file will be automatically opened on demand, when the stream is first read.
getter/setter pair
sourceFilePart ↔ int
If the source is a file, then this property can be used to stream one part of the file. The SourceFilePartSize property defines the size (in bytes) of each part. The SourceFilePart and SourceFilePartSize have default values of 0, which means the entire SourceFile is streamed.
getter/setter pair
sourceFilePartSize ↔ int
If the source is a file, then this property, in conjunction with the SourceFilePart property, can be used to stream a single part of the file. This property defines the size (in bytes) of each part. The SourceFilePart and SourceFilePartSize have default values of 0, which means that by default, the entire SourceFile is streamed.
getter/setter pair
stringBom ↔ bool
If true, then include the BOM when creating a string source via SetSourceString where the charset is utf-8, utf-16, etc. (The term BOM stands for Byte Order Mark, also known as the preamble.) Also, if true, then include the BOM when writing a string via the WriteString method. The default value of this property is false.
getter/setter pair
stringCharset ↔ String
Indicates the expected character encoding, such as utf-8, windows-1256, utf-16, etc. for methods that read text such as: ReadString, ReadToCRLF, ReadUntilMatch. Also controls the character encoding when writing strings with the WriteString method. The supported charsets are indicated at the link below.
getter/setter pair
verboseLogging ↔ bool
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
getter/setter pair
version → String
Version of the component/library, such as "10.1.0"
no setter
writeFailReason → int
This property is automatically set when a Write* method is called. It indicates the reason for failure. Possible values are:
no setter
writeTimeoutMs ↔ int
The maximum number of seconds to wait while writing. The default value is 30 seconds (i.e. 30000ms). A value of 0 indicates to return immediately if it is not possible to write to the sink immediately.
getter/setter pair

Methods

dispose() → void
Releases the native object now instead of waiting for garbage collection.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readBd(CkBinData binData) → void
Read as much data as is immediately available on the stream. If no data is immediately available, it waits up to ReadTimeoutMs milliseconds for data to arrive. The incoming data is appended to binData.
readBytesENC(String encoding) → String
The same as ReadBytes, except returns the received bytes in encoded string form. The encoding argument indicates the encoding, which can be base64, hex, or any of the multitude of encodings indicated in the link below.
readNBytesENC(int numBytes, String encoding) → String
The same as ReadNBytes, except returns the received bytes in encoded string form. The encoding argument indicates the encoding, which can be base64, hex, or any of the multitude of encodings indicated in the link below.
readSb(CkStringBuilder sb) → void
Read as much data as is immediately available on the stream. If no data is immediately available, it waits up to ReadTimeoutMs milliseconds for data to arrive. The data is appended to sb. The incoming bytes are interpreted according to the StringCharset property. For example, if utf-8 bytes are expected, then StringCharset should be set to utf-8 prior to calling ReadSb.
readString() → String
Read as much data as is immediately available on the stream. If no data is immediately available, it waits up to ReadTimeoutMs milliseconds for data to arrive. The data is returned as a string. The incoming bytes are interpreted according to the StringCharset property. For example, if utf-8 bytes are expected, then StringCharset should be set to utf-8 prior to calling ReadString.
readToCRLF() → String
Reads the stream until a CRLF is received. If no data is immediately available, it waits up to ReadTimeoutMs milliseconds for data to arrive. The data is returned as a string. The incoming bytes are interpreted according to the StringCharset property. For example, if utf-8 bytes are expected, then StringCharset should be set to utf-8 prior to calling ReadString.
readUntilMatch(String matchStr) → String
Reads the stream until the string indicated by matchStr is received. If no data is immediately available, it waits up to ReadTimeoutMs milliseconds for data to arrive. The data is returned as a string. The incoming bytes are interpreted according to the StringCharset property. For example, if utf-8 bytes are expected, then StringCharset should be set to utf-8 prior to calling ReadString.
reset() → void
Resets the stream. If a source or sink is open, then it is closed. Properties such as EndOfStream and IsWriteClose are reset to default values.
setSourceString(String srcStr, String charset) → void
Sets the stream's source to the contents of srcStr. The charset indicates the character encoding to be used for the byte representation of the srcStr.
toString() → String
A string representation of this object.
override
writeBd(CkBinData binData) → void
Writes the contents of binData to the stream.
writeByte(int byteVal) → void
Writes a single byte to the stream. The byteVal must have a value from 0 to 255.
writeBytes2(Uint8List byteData) → void
Writes binary bytes to a stream.
writeBytesENC(String byteData, String encoding) → void
Writes binary bytes to a stream. The byte data is passed in encoded string form, where the encoding can be base64, hex, or any of the supported binary encodings listed at the link below.
writeClose() → void
Indicates that no more data will be written to the stream.
writeSb(CkStringBuilder sb) → void
Writes the contents of sb to the stream. The actual bytes written are the byte representation of the string as indicated by the StringCharset property. For example, to write utf-8 bytes, first set StringCharset equal to utf-8 and then call WriteSb.
writeString(String str) → void
Writes a string to a stream. The actual bytes written are the byte representation of the string as indicated by the StringCharset property. For example, to write utf-8 bytes, first set StringCharset equal to utf-8 and then call WriteString.

Operators

operator ==(Object other) → bool
The equality operator.
inherited