Created
June 17, 2015 17:58
-
-
Save maslevx/b25cfaa4a5d35b3a66bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<byte[]> LazyReadBinaryFile(string fileName, int recordLen) | |
{ | |
byte[] buffer = new byte[recordLen]; | |
using (var stream = File.OpenRead(fileName)) | |
{ | |
long remaining = stream.Length; | |
int read = 0; | |
while (remaining > 0) | |
{ | |
int c = stream.Read(buffer, read, recordLen - read); | |
remaining -= c; | |
read += c; | |
if (read == recordLen) | |
{ | |
read = 0; | |
byte[] rtn = new byte[recordLen]; | |
Buffer.BlockCopy(buffer, 0, rtn, 0, recordLen); | |
yield return rtn; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment