I/O - Stream

Card Puncher Data Processing

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)

Note:

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.

Stream

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.

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.

Transformation

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

Model

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

Input

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

Io Input Stream

Output

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

Type

Standard

See IO - Standard streams (stdin, stdout, stderr)

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.

Documentation / Reference

Task Runner