Working with streams
A stream is a sequence of bytes that can be stored locally in memory, in a file, a pipe, remotely on the network, or other conceivable sources. .NET abstracts this concept with a class called Stream
, which provides support for reading from and writing to a stream. On the other hand, the streams are conceptually grouped into three categories:
- Backing store: These are streams that represent the source or the destination of a sequence of bytes. They are an endpoint for input or output data such as a file or network. Backing store streams work at the byte level. .NET provides classes such as
FileStream
,MemoryStream
, andNetworkStream
to implement backing stores. - Decorators: These are streams that read or write data from or to another stream, transforming it in some way. Like backing stores, they work with bytes. Decorators can be chained together. .NET provides decorator streams such as
BufferedStream
,CryptoStream
,DeflateStream
, andGZipStream
. - Adapters...