How to deterministically find the name of a crdownload file

304 views
Skip to first unread message

Ross Jacobs

unread,
Dec 13, 2019, 2:35:11 AM12/13/19
to Chromium Extensions
Problem

Due to the way that Chrome handles partial downloads and the downloads API, it does not seem possible to get the filepath of a specific downloaded file.

Background

I am writing an extension that downloads files. These are packet captures, which are used to solve network problems. Packet captures consist of a list of self-contained packets, so 10% of a downloaded file could be as useful as 20% if the data you're looking for is in the first 10%.

I use downloads API to specify the filename I want, but the file I see is ~ "Unconfirmed 123456.crdownload".
I am using the native messaging API as well, but it receives the filename, which is different from the partial download's name.

Potential Solutions

* If the crdownload number is deterministic, I could use that with the path of the download folder
* At worst, I can use the native messaging API to monitor the download folder for new files and callback the content script if there is one (with first ~8 bytes matching pcap format)

Question

What is the best way to determine the filepath of a partial download that your extension initiated?

Ross Jacobs

unread,
Dec 16, 2019, 2:27:42 PM12/16/19
to Chromium Extensions
According to the source code, this is a pseudo-random number:

/chrome/browser/download/download_target_determiner.cc
> 929 base::FilePath::StringType file_name = base::StringPrintf( > 930 unconfirmed_format.c_str(), > 931 base::RandInt(0, kUnconfirmedUniquifierRange));
Reply all
Reply to author
Forward
0 new messages