What is a stream? Difference between text and binary streams
A logical interface to a file is known as a stream. A stream is a flow of data from input and output devices to computer and computer to input or output devices. A flow of characters from an input device to a computer is called an input stream.
A sequence of the flow of characters from the computer to the output device is called an output stream. A stream is associated with a file using an open operation. By using a close operation, a stream is disassociated from the file.
Types of Stream
There are two types of streams in the C language
Text Stream
It is a collection of sequences of characters. Character translation may be done in a text stream, but in a binary stream, translation cannot be done.
For example, a new line may be converted to a carriage return/line feed pair It means that there may not be a one-to-one relationship between the written characters and the characters in an external device.
Binary Stream
It is a sequence of bytes. In the binary stream, translation is not done. It exists with one-to-one correspondence with external devices. The number of bytes can be written or read as the same as the number of bytes on the external device. However, an Implementation-defined number of bytes may be appended to a binary stream.
Difference between Text and Binary Stream
The difference between the text stream and the binary stream is as follows:
Text Stream | Binary Stream |
It is a sequence of characters. | It is a sequence of bytes. |
It does not have a one-to-one relationship with external devices. | It has a one-to-one relationship with external devices |
A certain character translation may occur in the text stream | No translation occurs in the binary stream. |
It is less efficient than a binary stream. | It is more efficient than a text stream. |
It can be used only for text data. | It can be used for different types of data. |
This types of file create problems with portability. | This type of file can easily be portable. |
If any error occurs in the text file, it can be easily found and eliminated. | Errors in the binary files cannot be easily recognized, they corrupt the binary file. |
In the text file, there are special characters at the end of a file that signals the EOF to the program. | In Binary files, there are special characters to signal EOF. |
Leave a Reply