I am using CEFsharp 107.1.50 and trying to tee an active download, i.e. look at what is being downloaded while the download is running, and stop the download if what I am interested in was found. For the purpose of this discussion, let's say the download is 100 GB and what I am interested in might be in the first 500 or so MB.
AFAIK there is no way to get an instance of System.IO.Stream for an active download, but I have found that if I have a download handler like this:
- Code: Select all
protected override void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
callback.Continue("C:\\TEMP\\test.bin", false);
}
And another program, right now just a separate console application for testing purposes, like this:
- Code: Select all
static void Main(string[] args)
{
try
{
using (FileStream fs = new FileStream("C:\\TEMP\\test.BIN", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
Console.WriteLine("I have the handle");
Console.ReadLine();
byte[] tmp = new byte[1024];
while (true)
{
Console.WriteLine(fs.Length);
fs.Seek(fs.Length - 1024, SeekOrigin.Begin);
int read = fs.Read(tmp, 0, 1024);
Console.WriteLine("I read {0:n0} bytes", read);
for (int i = 0; i < read; i++)
Console.Write("{0:x2}, ", tmp[i]);
Console.WriteLine("Press enter.");
Console.ReadLine();
}
}
} catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
}
}
I can actually open and read the file while the download is in progress. As expected, the length of the file keeps growing. It seems like CEF doesn't keep a tight lock on it. That's great.
My question: Can I depend on this behavior - being able to open the file that is being downloaded while the Chromium engine is still writing to it - as being officially supported, or is it just luck?
Also I found that this PHP script:
- Code: Select all
<?php
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename="fuck.exe"');
for(;;){
if (connection_aborted()) die();
echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
flush();
usleep(5000);
}
i.e. a download where the server doesn't know the final size, makes downloadItem.TotalBytes return 0. Is this the intended behavior of CEF/CEFsharp? Would it not be more sensible to return something like -1, to mean "I don't know the total bytes"?
PS: To the forum admins, your mail server may be broken. Mails from the forum get marked as phishing attempts.
- Code: Select all
Authentication-Results: mailin037.protonmail.ch; dmarc=fail (p=quarantine dis=none) header.from=magpcss.org