internal StreamReadBuffer(Stream source, int initialSize, int maxSize, bool minimalRead)
{
StreamWrapper wrapper;
if (!_lockObjects.TryGetValue(source, out wrapper))
{
_lockObjects.Add(source, new StreamWrapper { Source = source });
wrapper = _lockObjects[source];
if (source.CanSeek)
{
// assume that this is a quick operation
wrapper.EofOffset = source.Length;
}
}
else
{
wrapper.RefCount++;
}
// make sure our initial size is a power of 2 (this makes resizing simpler to understand)
initialSize = 2 << (int)Math.Log(initialSize - 1, 2);
// make sure our max size is a power of 2 (in this case, just so we report a "real" number)
maxSize = 1 << (int)Math.Log(maxSize, 2);
_wrapper = wrapper;
_data = new byte[initialSize];
_maxSize = maxSize;
_minimalRead = minimalRead;
_savedBuffers = new List<SavedBuffer>();
}