A
Andrew
I am currently using the following code to store a stream into a binary
database field. This works but I want to start reading from a compressed
stream where I will not know the length.
Is there any way to add the bytes chunk by chunk until there is none left to
read? Rather like the way that you extract the data.
I know I could compress it all to a memory stream first and then I would
know the length of the memory stream but that means using double the amount
of memory.
Code I am using to write the data
----------------------------------
byte[] Bytes = new byte[SourceStream.Length];
SourceStream.Read(Bytes, 0, Bytes.Length);
SQLCommand.Parameters.Add("@MyField", SqlDbType.Image).Value = Bytes;
Code I am using to read the data
----------------------------------
const int BufferSize = 1024;
byte[] Bytes = new byte[BufferSize];
long StartIndex = 0;
long ReadCount = 0;
do
{
StartIndex += ReadCount;
ReadCount = DataReader.GetBytes(0, StartIndex, Bytes, 0, BufferSize);
if (ReadCount > 0)
OutStream.Write(Bytes, 0, (int)ReadCount);
}
while (ReadCount == BufferSize);
Thanks
database field. This works but I want to start reading from a compressed
stream where I will not know the length.
Is there any way to add the bytes chunk by chunk until there is none left to
read? Rather like the way that you extract the data.
I know I could compress it all to a memory stream first and then I would
know the length of the memory stream but that means using double the amount
of memory.
Code I am using to write the data
----------------------------------
byte[] Bytes = new byte[SourceStream.Length];
SourceStream.Read(Bytes, 0, Bytes.Length);
SQLCommand.Parameters.Add("@MyField", SqlDbType.Image).Value = Bytes;
Code I am using to read the data
----------------------------------
const int BufferSize = 1024;
byte[] Bytes = new byte[BufferSize];
long StartIndex = 0;
long ReadCount = 0;
do
{
StartIndex += ReadCount;
ReadCount = DataReader.GetBytes(0, StartIndex, Bytes, 0, BufferSize);
if (ReadCount > 0)
OutStream.Write(Bytes, 0, (int)ReadCount);
}
while (ReadCount == BufferSize);
Thanks