Remove the interface IStream used for custom stream implementations that works with DataStream. Now every Stream implementation can be used directly with a DataStream. This includes DataStream itself as a sub-stream as it was before. We are adding a new constructor that takes Stream directly, this simplifies the implementation and usage.
As a indirect consequence, the performance increases in some cases as there isn't anymore an indirect interface or base class (StreamWrapper) layer to use regular streams.
There is a small fix where the methods Read and Write of DataWriter now throw an exception if the cout and index of the buffer are out of bound even if the count is zero.
We keep the StreamWrapper layer to facilitate the implementation of custom streams like RecyclableMemoryStream and LazyFileStream. This wrapper layer is just a basic implementation of Stream that forwards every method to the base stream methods unless they are overwritten in the implementation. The StreamWrapper now is abstract as it didn't make sense to use without an implementation on top.
Migration
Unless you have implemented a custom stream that works with DataStream, you don't need to do anything. Otherwise, replace the implementation of IStream with Stream.
Example
Now we can create a DataStream object directly from a Stream. These methods are equivalent.
var baseStream = new MemoryStream();
var stream1 = DataStreamFactory.FromStream(baseStream);
var stream2 = new DataStream(baseStream);
We can also do the same as before from another DataStream (as it inherits from Stream). Create a custom implementation of Stream and using it with a DataStream is easier as there isn't anymore the IStream.
Performance
In general there is an increase of performance using DataStream.
Description
Remove the interface
IStream
used for custom stream implementations that works withDataStream
. Now everyStream
implementation can be used directly with aDataStream
. This includesDataStream
itself as a sub-stream as it was before. We are adding a new constructor that takesStream
directly, this simplifies the implementation and usage.As a indirect consequence, the performance increases in some cases as there isn't anymore an indirect interface or base class (
StreamWrapper
) layer to use regular streams.There is a small fix where the methods
Read
andWrite
ofDataWriter
now throw an exception if the cout and index of the buffer are out of bound even if the count is zero.We keep the
StreamWrapper
layer to facilitate the implementation of custom streams likeRecyclableMemoryStream
andLazyFileStream
. This wrapper layer is just a basic implementation ofStream
that forwards every method to the base stream methods unless they are overwritten in the implementation. TheStreamWrapper
now is abstract as it didn't make sense to use without an implementation on top.Migration
Unless you have implemented a custom stream that works with
DataStream
, you don't need to do anything. Otherwise, replace the implementation ofIStream
withStream
.Example
Now we can create a
DataStream
object directly from aStream
. These methods are equivalent.We can also do the same as before from another
DataStream
(as it inherits fromStream
). Create a custom implementation ofStream
and using it with aDataStream
is easier as there isn't anymore theIStream
.Performance
In general there is an increase of performance using
DataStream
.Before:
After: