Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' <summary>
- ''' Reads a file into chunks
- ''' </summary>
- ''' <param name="fileName">The name for the file to read</param>
- ''' <param name="bufferLength">The length for the buffer to use; indicates how large the chunks read will be</param>
- ''' <param name="encoding">Encoding to use to read the file</param>
- ''' <returns>An IEnumerable of string. Every element contains one chunk of data read, equalling the buffer length in size</returns>
- Private Shared Function ReadFile(ByVal fileName As String, ByVal bufferLength As Int32, ByVal encoding As Encoding) As IEnumerable(Of String)
- Dim result = New List(Of String)
- Using fileStream = File.OpenRead(fileName)
- Const offset = 0
- Dim buffer(bufferLength) As Byte
- Dim bytesRead As Int32
- While (True)
- bytesRead = fileStream.Read(buffer, offset, buffer.Length)
- If bytesRead = 0 Then
- Exit While
- End If
- result.Add(encoding.GetString(buffer))
- End While
- End Using
- Return result
- End Function
Advertisement
Add Comment
Please, Sign In to add comment