We are developing with Unity.
I created a download handler that inherits the DownloadHandlerScript class.
private class FileDownloadHandler : DownloadHandlerScript
{
FileStream fs;
int offset = 0;
int length = 0;
public FileDownloadHandler(string path, byte[ ] buffer)
: base(buffer)
{
fs = new FileStream(path, FileMode.Create, FileAccess.Write);
}
protected override bool ReceiveData(byte[ ] data, int dataLength)
{
fs.Write(data, 0, dataLength);
offset += dataLength;
return true;
}
protected override void CompleteContent()
{
fs.Flush();
fs.Close();
}
protected override void ReceiveContentLength(int contentLength)
{
length = contentLength;
}
protected override float GetProgress()
{
if (length == 0)
return 0.0f;
return (float)offset / length;
}
}
If you improve this and interrupt foul download for some reason,
I would like to be able to restart the file download.
The communication process is as follows.
{
UnityWebRequest www = new UnityWebRequest(a_url);
byte[ ] l_bytes = new byte[300 * 1024];
www.downloadHandler = new FileDownloadHandler( _path, l_bytes);
while ()
{
_loadingProgress = www.downloadProgress;
yield return null;
}
l_bytes = null;
}
How should I secure the files that were read halfway and set the communication restart point?
Thank you.