Seeking forwards is easy enough (just read), but you can't seek backwards without buffering. Maybe just:
using(var ms = new MemoryStream()) {
otherStream.CopyTo(ms);
ms.Position = 0;
// now work with ms
}
This, however, is only suitable for small-to-moderate streams (not GB), that are known to end (which streams are not requires to do). If you need a larger stream, a FileStream
to a temp-file would work, but is significantly more IO-intensive.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…