What is a stream?

Asked

Viewed 6,409 times

13

In both PHP and C#, languages I’ve been using in my day to day life, I’ve come across a common term: Stream.

Whenever 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 via streaming".

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 obtaining in a string the contents of a resource open by function fopen.

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

Summing up my doubt:

  • What is the meaning of Stream after all?

  • I was wondering if this stream PHP and Csharp have something to do with "streaming videos" from sites like Youtube.

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

  • 3

    I hear a lot about stream when they talk about Java 8... I also want to know! Good question

  • 2
  • 2

    The crowd that is negatively answering the questions could explain the reason for the negative. Thus, we could increase the intellectual level of the questions of the site, knowing where the defect is and correcting what needs to be improved.

2 answers

10


Almost everything has been answered in How To Really Understand Streams?.

Nothing to do with video streaming directly, although the technique is the same. You access a feature that gives you the information you want as you request it, the exact way it occurs doesn’t matter.

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

Java 8 has invented such a Stream that it’s still a mechanism like this that we’re talking about, but it’s used in another context, it’s almost the same as the LINQ of C#, it’s a way to manipulate enumerable on demand.

3

I will try to respond in a generic way, with no direct connection to a specific language. I do not understand Stream as a specific feature of a language, but rather a technique/algorithm.

What is the meaning of Stream after all?

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

I was wondering if this stream of PHP and Csharp has anything to do with "streaming videos" from sites like Youtube.

As clarified with the answer to your previous question, yes, because it is about transferring content/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 are coming to you as they are made available by a server. So in my opinion yes, even if not all languages are for the web, or allow content transfer of dynamic sizes, or even have a class called Stream, stream in this case is only a name given to this technique.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.