fsp bug fix
This commit is contained in:
parent
0275ef1bb1
commit
96feda06e1
@ -37,7 +37,7 @@ public class FSP
|
|||||||
{
|
{
|
||||||
filePath_client.ThrowIfEscapes();
|
filePath_client.ThrowIfEscapes();
|
||||||
using System.IO.Stream fileStream = File.OpenWrite(filePath_client);
|
using System.IO.Stream fileStream = File.OpenWrite(filePath_client);
|
||||||
Download_SharedCode(fileStream);
|
DownloadToStream(fileStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] DownloadFileToMemory(IOPath filePath_server)
|
public byte[] DownloadFileToMemory(IOPath filePath_server)
|
||||||
@ -54,11 +54,11 @@ public class FSP
|
|||||||
public byte[] DownloadFileToMemory()
|
public byte[] DownloadFileToMemory()
|
||||||
{
|
{
|
||||||
using var fileStream = new System.IO.MemoryStream();
|
using var fileStream = new System.IO.MemoryStream();
|
||||||
Download_SharedCode(fileStream);
|
DownloadToStream(fileStream);
|
||||||
return fileStream.ToArray();
|
return fileStream.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Download_SharedCode(System.IO.Stream fileStream)
|
public void DownloadToStream(System.IO.Stream fileStream)
|
||||||
{
|
{
|
||||||
lock (MainSocket)
|
lock (MainSocket)
|
||||||
{
|
{
|
||||||
@ -67,13 +67,13 @@ public class FSP
|
|||||||
if (Filesize < 0)
|
if (Filesize < 0)
|
||||||
throw new Exception("FileSize < 0");
|
throw new Exception("FileSize < 0");
|
||||||
MainSocket.SendPackage("ready");
|
MainSocket.SendPackage("ready");
|
||||||
int recievedCount;
|
|
||||||
do
|
while (BytesDownloaded < Filesize)
|
||||||
{
|
{
|
||||||
recievedCount = MainSocket.Receive(buffer);
|
int recievedCount = MainSocket.Receive(buffer);
|
||||||
fileStream.Write(buffer, 0, recievedCount);
|
fileStream.Write(buffer, 0, recievedCount);
|
||||||
BytesDownloaded += recievedCount;
|
BytesDownloaded += recievedCount;
|
||||||
} while (recievedCount == buffer.Length);
|
}
|
||||||
|
|
||||||
if (BytesDownloaded != Filesize)
|
if (BytesDownloaded != Filesize)
|
||||||
throw new Exception($"expected {Filesize} bytes, but downloaded {BytesDownloaded} bytes");
|
throw new Exception($"expected {Filesize} bytes, but downloaded {BytesDownloaded} bytes");
|
||||||
@ -91,13 +91,13 @@ public class FSP
|
|||||||
{
|
{
|
||||||
MainSocket.SendPackage(BitConverter.GetBytes(Filesize));
|
MainSocket.SendPackage(BitConverter.GetBytes(Filesize));
|
||||||
MainSocket.GetAnswer("ready");
|
MainSocket.GetAnswer("ready");
|
||||||
int readCount;
|
|
||||||
do
|
while (BytesUploaded < Filesize)
|
||||||
{
|
{
|
||||||
readCount = fileStream.Read(buffer, 0, buffer.Length);
|
int readCount = fileStream.Read(buffer, 0, buffer.Length);
|
||||||
MainSocket.Send(buffer, 0, readCount, SocketFlags.None);
|
MainSocket.Send(buffer, 0, readCount, SocketFlags.None);
|
||||||
BytesUploaded += readCount;
|
BytesUploaded += readCount;
|
||||||
} while (readCount == buffer.Length);
|
}
|
||||||
|
|
||||||
if (BytesUploaded != Filesize)
|
if (BytesUploaded != Filesize)
|
||||||
throw new Exception($"expected {Filesize} bytes, but uploaded {BytesDownloaded} bytes");
|
throw new Exception($"expected {Filesize} bytes, but uploaded {BytesDownloaded} bytes");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user