I need to read some bytes at known file offset in very big files (gigabytes). Now I am using this:
Using fsSrc As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, MAX_BUFFER)
For i = 0 To k.startas.Count - 1
currentpos = fsSrc.Seek(k.startas(i), SeekOrigin.Begin)
currentpos = fsSrc.Read(buferis, 0, 32)
k.ilgis(i) = buferis(8) + buferis(9) * 256 + &H16
Next
End Using
This portion is very slow, constant MAX_BUFFER is quite big, but this this is slow operation. Even finding and indexing of the file is faster- there I read megabyte chunks of file and search inside for indexes. But opening file and seeking to position is very slow. It is not random read- I sort “k” database that all reading points are in a row and no need to “rewind” the file position.
There is another part in program working in the same manner- reading chunks of data with random length from known positions and writing to the other file. And it is very slow too. The algorithm is tha same- seek, read, write.