Generic stream I/O functions

The following table shows the generic stream I/O functions of the DataBlade® API. You can use these generic stream I/O functions on any stream (as long as the stream class implements them).
Table 1. Generic stream I/O functions
Stream-I/O function Description
mi_stream_close() Close the stream.
mi_stream_eof() Check the stream for the end-of-stream condition.
mi_stream_get_error() Obtain the last error that occurred on the specified stream.
mi_stream_getpos() Obtain the current stream seek position, returning it in a function parameter.
mi_stream_length() Obtain the length of the stream data.
mi_stream_read() Read a specified number of bytes from the stream.
mi_stream_seek() Move the stream seek position to the desired location.
mi_stream_set_error() Sets the last error status on the specified stream.
mi_stream_setpos() Set the stream seek position.
mi_stream_tell() Obtain the current stream seek position, returning it from the function.
mi_stream_write() Write a specified number of bytes to the stream.

The advantage of accessing data through a stream is that the call to the generic stream I/O function is the same, regardless of the format of the underlying data. With these generic stream-I/O functions, the DataBlade API provides a common interface for the transportation and access of data independent of the data type or destination.

For example, the following call to mi_stream_read() reads 164 bytes of data from a stream into a user-defined buffer named buf:
nbytes_read = mi_stream_read(strm_desc, buf, 164);

The calling code does not need to concern itself about the format of the underlying data. Whether mi_stream_read() reads the data from a file, character array, varying-length structure, or user-defined stream depends on which stream-open function has obtained the pointer to the stream descriptor (MI_STREAM structure).

In addition to the generic stream I/O functions in the preceding table, the stream I/O interface contains the following functions for different stream classes.

Classes of stream I/O function Stream I/O function More information
Stream-open functions for the predefined stream classes: Using predefined stream classes
  • File stream
  • String stream
  • Varying-length-data stream
  • mi_stream_open_fio()
  • mi_stream_open_mi_lvarchar()
  • mi_stream_open_str()
Abstract stream I/O functions for user-defined streams mi_stream_init()

Type-specific stream-open function

Create a user-defined stream class