What is stream?

Both in PHP and in C#, languages that lately I have used in my day to day, I have come across a common term: Stream.

Always when I hear the word Stream, the first thing that comes to mind is Youtube, among other sites, which are usually called "sites that stream video".

But in the languages mentioned above, the term is usually related to reading and writing data in memory or in a file.

For example, in PHP we have a function called stream_get_contents which is responsible for getting in a string the contents of a resource opened by the function fopen.

Already in C# I ended up bumping into this term when I needed to use the Class FileStream and MemoryStream, which reminded me a little the wrappers that PHP uses to read the output buffer, files or even the memory itself (through the wrapper php://output, php://memory and related).

Summarizing my doubt:

  • What is the meaning of Stream after all?

  • I was wondering if this Stream of PHP and Csharp has any relation to the "streaming of videos" of sites like Youtube.

  • All languages that work with data manipulation, such as files, temporary files, memory, or output buffer, also use this Stream?

Author: Maniero, 2017-08-08

2 answers

Almost everything has already been answered in How to really understand Streams?.

Nothing to do with streaming video directly, although the technique is the same. You access a resource that will give you the information you want as you request, the exact way it occurs does not matter.

In general languages do not have streams , libraries yes, so anyone can have. The most modern have in the standard library. You can create your streams .

Java 8 invented such a Stream that does not cease to be a mechanism like this we are talking about, but it is used in another context, it is almost the same as the LINQ of C#, it is a way of manipulating enumerables on demand.

 10
Author: Maniero, 2017-08-10 11:05:23

I will try to answer in a generic way, without direct link to a specific language. I don't understand Stream as a language-specific feature, but rather a technique/algorithm.

What Is The Meaning Of Stream after all?

As the free translation itself explains, Stream is a stream, it is a data stream, in programming languages in general it is about transferring a content/bytes of known or not size from one "location" to another, local in this case it is always related to the hardware (ram, hdd, flash, usb, ethernet, etc.) even if it is virtualized, internally this communication is usually carried out via OS.

I wanted to know if this PHP and Csharp stream has any relation to the" video streaming " of sites like Youtube.

As clarified with the answer to your previous question, yes, since it is about transferring contents / bytes from one point to another.

All languages that work with data manipulation, such as files, temporary files, memory, or output buffer, also use this Stream?

In this case we need to clarify that there are Streams that you already know the size, a disk file for example, and there are streams such as sound and image that come to the point that they are made available by a server. So in my opinion yes, although not all languages are for the web, or allow transfer of contents of dynamic sizes, or that do not even have a class called Stream, stream in this case is only a name given to this technique.

 3
Author: alexandre.katrid, 2017-08-10 18:48:42