The second parameter to Read and Write are the offset within the array, not the offset within the file. Every time you read data you want to place it in the array starting from the first element, so that parameter value should be zero every time.
Also, the third parameter to Write is the number of bytes to write. You're trying to write 1024 every time but what if you didn't read 1024 bytes in the first place. I suggest that you change this:to somethinglike this:VB Code:
While True bytesRead = compressedData.Read(buffer, offset, 1024) 'Attempt a 1K read If bytesRead = 0 Then 'Fail if no data left Exit While End If outData.Write(buffer, offset, 1024) 'Write the 1K to file offset += bytesRead totalBytes += bytesRead End WhileAlso, you don't need that Finally block at all. You should get to grips with the Using statement, which will implicitly dispose your objects whether there's an exception thrown or not.VB Code:
bytesRead = compressedData.Read(buffer, 0, buffer.Length) While bytesRead > 0 outData.Write(buffer, 0, bytesRead) bytesRead = compressedData.Read(buffer, 0, buffer.Length) End While




Reply With Quote