Yes, it is possible, but the only precaution you need to have is to ensure that none of the two streams are recorded in one place in the file, otherwise the contents of the file will be incorrect.
FileStream writeStream = new FileStream(destinationPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write); writeStream.Position = startPositionOfSegments; //REMEMBER This piece of calculation is important // A simple function to write the bytes ... just read from your source and then write writeStream.Write(ReadBytes, 0 , bytesReadFromInputStream);
After each Write we used writeStream.Flush(); so that buffered data is written to a file, but you can change as per your requirement.
Since you already have code that loads file segments in parallel. The only change you need to make is just to open the file stream as described above, and instead of creating many segment files locally, just open the stream for one file.
startPositionOfSegments very important and computes it perfectly, so that neither of the two segments overwrites the downloaded uploaded bytes to the same place in the file, otherwise it will give an incorrect result.
The above procedure works fine, but it can be a problem if the size of your segment is too small (we also encountered this, but after increasing the size of the segments it became fixed). If you encounter any exception, you can also synchronize only the Write part.
dbw
source share