I'm trying to convert a chunk of data from 8-bit packing to 7-bit packing using Bill Koukoutsis' BitStream library from CodeProject.com which still seems to be the go-to source for this kind of thing in C#. The code I'm using is as follows (fs is a filestream initialized outside of the code):
for (int block = 0; block < count; block++)
{
var theBlock = fetcher(block);
if (theBlock.Any(x => (x != 0)))
{
Console.Write("Good Block =>");
}
else
{
Console.Write("Zero block =>");
}
var sevenBitSize = theBlock.Length - (theBlock.Length/8);
var theCodedBlock = new byte[sevenBitSize];
var ms = new MemoryStream(theCodedBlock);
BitStream bms = ms;
using (bms)
{
foreach (byte t in theBlock)
{
bms.Write(t, 0, 7);
}
bms.WriteTo(fs);
}
if (theCodedBlock.Any(x => (x != 0)))
{
Console.Write("Good Block\n");
}
else
{
Console.Write("Zero block\n");
}
}
When run, this produces a constant stream of "Good Block => Zero Block". So for some reason the BitStream is outputting zeroes into the theCodedBlock array. It seems to work ok for reading values from a memory array elsewhere in the code, so am I doing something wrong or is this a BitStream bug?