B
Big Daddy
There's an example in the .NET documentation of using GZipStream to
decompress a byte array:
http://msdn.microsoft.com/en-us/library/as1ff51s.aspx
In the example, the data is read out of the stream 100 bytes at a time
in a while loop until it's finished:
private const int buffer_size = 100;
public static int ReadAllBytesFromStream(Stream stream, byte[]
buffer)
{
// Use this method is used to read all bytes from a stream.
int offset = 0;
int totalCount = 0;
while (true)
{
int bytesRead = stream.Read(buffer, offset, buffer_size);
if (bytesRead == 0)
{
break;
}
offset += bytesRead;
totalCount += bytesRead;
}
return totalCount;
}
int totalCount = GZipTest.ReadAllBytesFromStream(zipStream,
decompressedBuffer);
Why isn't it read out in one fell swoop like this:
int bytesRead = stream.Read(buffer, offset, buffer.length);
I have tried it and it seems to work. The code would be cleaner and
run faster, but it makes me worried that there was a good reason for
reading it out 100 bytes at a time in the documentation.
Any ideas?
thanks in advance,
John
decompress a byte array:
http://msdn.microsoft.com/en-us/library/as1ff51s.aspx
In the example, the data is read out of the stream 100 bytes at a time
in a while loop until it's finished:
private const int buffer_size = 100;
public static int ReadAllBytesFromStream(Stream stream, byte[]
buffer)
{
// Use this method is used to read all bytes from a stream.
int offset = 0;
int totalCount = 0;
while (true)
{
int bytesRead = stream.Read(buffer, offset, buffer_size);
if (bytesRead == 0)
{
break;
}
offset += bytesRead;
totalCount += bytesRead;
}
return totalCount;
}
int totalCount = GZipTest.ReadAllBytesFromStream(zipStream,
decompressedBuffer);
Why isn't it read out in one fell swoop like this:
int bytesRead = stream.Read(buffer, offset, buffer.length);
I have tried it and it seems to work. The code would be cleaner and
run faster, but it makes me worried that there was a good reason for
reading it out 100 bytes at a time in the documentation.
Any ideas?
thanks in advance,
John