Closed besoft closed 6 years ago
This class represents an obsolete workaround I needed to get the initial prototype running. The current implementation (including the nuget package) shouldn't depend on it.
Buffering a gigabyte sized stream in a temp file isn't a good idea in the first place so I'm not going to "fix" that workaround.
While System.IO.Stream uses long data type for determining the length of the stream and seeking in it, which allows processing streams larger than 2GB, BufferedStream, which is a wrapper over System.IO.Stream uses int for its private fields mOffset, mEnding, and mLength. Due to using checked keyword in the ctor when casting long to int, processing of streams larger than 2GB ends with an OverflowException.
There is apparently no reason for using int and, therefore, it should be changed. The changes in BufferedStream are as follows.
1) Lines 18-20: private int mOffset; private int mEnding; private int mLength; => private long mOffset; private long mEnding; private long mLength;
2) Line 31 mLength = checked((int)stream.Length); => mLength = stream.Length; 3) Line 79 mOffset = (int)value; => mOffset = value; 4) Line 121 count = mBuffer.Read(buffer, offset, Math.Min(count, mEnding - mOffset)); => count = mBuffer.Read(buffer, offset, (int)Math.Min((long)count, mEnding - mOffset));