I have a stream that contains many pieces of data. I want to expose just a piece of that data in another stream. The piece of data I want to extract can often be over 100mb. Since I already have stream with the data in it it seems like a waste to copy that data to another stream and return that. What im looking for is a way to reference the data in the first stream while controlling how much of it the second stream can reference. Is this possible
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You need to make your own Stream class that validates its position and returns the desired subset.
I'm not aware of any built-in classes that do this.
Looks like StreamMuxer project was created with similar purpose in mind.
There is a good implementation of this by Mark Gravell detailed here. The code posted there is:
What exactly are you scared of duplicating? I doubt you have anything super performance critical, parse your Stream on the fly and use a MemoryStream till you find you need something else.