I have a 1GB in server A, I must use Read()
method to get it to local. It is splitted into packages (16517 package). Each package is 65536 bytes include header.
Current, I use BinaryWriter
to write each package into file directly. But it took me over 5 minutes (323642 ms).
I try to join some packages into byte[]
of 10MB, but it does not reduce time(317397 ms).
Which way is the best to write byte[]
into binary file?
Update
const ulong Memory_10MB = 10485760; // 10MB
do {
byte[] packetData = Read(&totalSize, /*Other parameters*/ ,&hasFollowing);
if (package == null) {
// Process error
return;
}
dataSize += (ulong)packetData.Length;
if (dataSize >= Memory_10MB)
{
if (binaryWriter == null)
{
path = Path.GetTempFileName();
fileStream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read);
binaryWriter = new BinaryWriter(fileStream);
if (responseData.Length > 5)
{
binaryWriter.Write(responseData.Skip(5).ToArray());
}
}
binaryWriter.Write(packetData);
}
else
{
responseData = Utilities.ConcatArrays(responseData, packetData);
}
} while (dataSize < totalSize);
// Process after got data