I am using the following code fragment in Powershell:
$fd = [System.IO.File]::OpenRead($file)
$buf = new-object byte[] (8MB)
$read_len = $fd.Read($buf,0,$buf.length)
Is there any chance the data that shows up in the buffer might not be what is actually on the drive? I haven't had a specific problem but I'm imagining possible issues with reading from USB or network drives.
The reason I ask is that I am reading the entire file and writing each buffer to a new file. I compute the MD5 hash as I read the file. But, if somehow the buffer was not actually the source file contents then the new file would have this same corruption and its MD5 would match the one I calculated while reading the original. This would give me the false impression that the copy was successful.
So, in short, is read buffer corruption even possible?