Попробуйте это:
void Main()
{
// you can run the commented code as test
// var bytes = new byte[]
// {0xC8, 0x6B, 0x02, 0x00, 0x55, 0x4E, 0x02, 0x00, 0xC8, 0x6B, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x81, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0xEC, 0x6A, 0x05, 0x00, 0x79, 0x75, 0x01, 0x88, 0x81, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x28,
// 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x01, 0x04,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF6, 0x5F, 0xA4, 0x59, 0x00, 0x00, 0x00, 0x00,
// 0xFF, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00,
// 0x40, 0x3C, 0x9F, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0xFF, 0xFF, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x06, 0xEA, 0xE8, 0x33, 0x35, 0x36};
// var testStream = new MemoryStream(bytes);
// var entries = SplitStream(testStream);
var fileStreamBufferSize = 1024 * 1024; // one megabyte, increasing this might speed up
using(var stream = new FileStream(@"C:\BitBucket\Datamining\WpfApp1\WpfApp1\zip.dat",
FileMode.Open,
FileAccess.Read,
FileShare.Read,
fileStreamBufferSize,
FileOptions.SequentialScan // SequentialScan helps os optimize for read
))
{
var entiries = SplitStream(stream);
}
}
private IEnumerable<KeyValuePair<int, IEnumerable<byte>>> SplitStream(Stream stream)
{
var buf = new byte[1024];
var entry = new List<byte>();
int readCount = 0;
var offset = 0;
var entryStartOffset = 0;
while((readCount = stream.Read(buf, 0, buf.Length)) > 0)
{
for(int i = 0; i < readCount; i++)
{
if(buf[i] == 0) // found entry end
{
if(entry.Count > 0) // check if we have values to return
{
yield return new KeyValuePair<int, IEnumerable<byte>>(entryStartOffset, entry);
entry.Clear();
}
}
else // add to current entry
{
if(entry.Count < 1) // if first value save start offset
{
entryStartOffset = offset;
}
entry.Add(buf[i]);
}
offset++;
}
}
if(entry.Count > 0) // if current entry not returned
{
yield return new KeyValuePair<int, IEnumerable<byte>>(entryStartOffset, entry);
}
}