I/O - Stream

> I/O - (Input/Output|Read/Write) - Data Access

1 - About

A stream concept at the io level is a file (generally a text file)

A stream is an abstract concept for files and io devices which can be read or written, or sometimes both.

I/O devices can be interpreted as streams, as they produce or consume potentially unlimited data over time.

Stream I/O (input/output) refers to the transfer of data either to or from a storage medium. Streams are a mean to manipulate the data that is read or written from and to a file (from byte to characters, object ,…).

For instance, a file content is an ordered collection of bytes and you manipulate this sequence of byte through the creation of a stream that gives you methods to read from and write to and from destinations such as:

When you work with a file system, you work with a path (directory or file)



3 - Asynchronous

Reading or writing a large amount of data can be resource-intensive. You should perform these tasks asynchronously if your application needs to remain responsive to the user. With synchronous I/O operations, the thread is blocked until the resource-intensive operation has completed. Use asynchronous I/O operations when developing apps to prevent creating the impression that your app has stopped working.

4 - Stream

4.1 - Data source and destination

A stream can represent many different kinds of:

  • sources
  • and destinations

that holds, generates, or consumes data.

For instance:

  • disk files,
  • another program,
  • a peripheral device,
  • or an (memory)array.

4.2 - Data Type

Typically, streams are designed for simple byte input and output but they can supports many different kinds of data including:

  • primitive data types,
  • localized characters,
  • and objects.

4.3 - Transformation

Some streams simply pass on data; others manipulate and transform the data.

4.4 - Model

All streams present the same simple model to programs that use them.

4.4.1 - Input

A program uses an input stream to read data sequentially (one item at time) from a source.

4.4.2 - Output

A program uses an output stream to write data sequentially (one item at time) to a destination.

5 - Type

5.1 - Standard

6 - Implementation

  • Several languages, such as Perl and Python, implement streams as iterators.
  • Alternative implementations of stream include data-driven languages, such as AWK and sed.

7 - Documentation / Reference