public static byte[] ReadBytes(this Stream s, int count) { if (count < 0) throw new ArgumentOutOfRangeException("count", "Non-negative number required."); var buffer = new byte[count]; s.ReadBytes(buffer, 0, count); return buffer; }