Stream Files Versus Database Files

To better understand stream files, it is useful to compare them with IBM® i database files.

On the integrated file system, a stream is simply a continuous string of characters. A database file is record arranged; It has predefined subdivisions consisting of one or more fields that have specific characteristics, such as length and data type.

Figure 1. Comparison of a Stream File and a Record-Oriented File

Default C/C++ stream I/O on the IBM i is simulated on top of an IBM i database file. Figure 2 illustrates how an IBM i record is mapped to a C/C++ stream. This is simulated stream file processing with IBM i records.

Figure 2. IBM i Records Mapping to a C/C++ Stream File
The differences in structure of stream files and record-oriented files affect how an application is written to interact with them and which type of file is best suited to an application.
  • A record-arranged file is well suited for storing customer information, such as name, address, and account balance. These fields can be individually accessed and manipulated using the extensive programming functions of the IBM i.
  • A stream file is better suited for storing information such as a customer's picture, which is composed of a continuous string of bits representing variations in color. Stream files are particularly well suited for storing strings of data such as the text of a document, images, audio, and video.