i totally out of element when comes binary files. need read binary file , break chunks using new line delimiter. have tried googling come empty. on appreciated. has opened binary file.
so have file of unknown encoding. need break out file chunks using \n newline delimiter. looking function can break out binary data new line delimiter.
helper method
class myenumerableextensions { //for source containing n delimiters, returns n+1 lists public static ienumerable<list<t>> spliton( ienumerable<t> source, t delimiter) { var list = new list<t>(); foreach (var item in source) { if (delimiter.equals(item)) { yield return list; list = new list<t>(); } else { list.add(item); } } yield return list; } } usage
i need read binary file , break chunks using new line delimiter.
var path = "binary-file.bin"; var delimiter = (byte)'\n'; var chunks = file.readallbytes(path) .spliton(delimiter) .tolist();
Comments
Post a Comment