add ReadToEnd function
This commit is contained in:
parent
c275c017c1
commit
9df55b9c08
@ -96,4 +96,33 @@ public static class StreamExtensions
|
|||||||
}
|
}
|
||||||
_streamPositions[st].Push(st.Position);
|
_streamPositions[st].Push(st.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const long BUFFER_SIZE=4096;
|
||||||
|
public static byte[] ReadToEnd(this Stream st)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
|
byte[] output = new byte[0];
|
||||||
|
int i = 0;
|
||||||
|
bool done = false;
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
int length = st.Read(buffer, 0, buffer.Length);
|
||||||
|
if (length == 0)
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length < BUFFER_SIZE)
|
||||||
|
{
|
||||||
|
Array.Resize<byte>(ref buffer, length);
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.Resize<byte>(ref output, output.Length + buffer.Length);
|
||||||
|
Array.Copy(buffer, 0, output, i, buffer.Length);
|
||||||
|
i += buffer.Length;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user