string
-Asset::hash (function<void (float)> progress) const
+Asset::hash(function<void (int64_t, int64_t)> progress) const
{
DCP_ASSERT (_file);
/** Calculate the hash of this asset's file, if it has not already been calculated,
* then return it
- * @param progress Function that will be called with a parameter between 0 and 1 to indicate
- * progress in the calculation
+ * @param progress Function that will be called with the number of bytes calculated
+ * and the total number of bytes
* @return the hash
*/
- std::string hash (boost::function<void (float)> progress = {}) const;
+ std::string hash(boost::function<void (int64_t, int64_t)> progress = {}) const;
void set_hash (std::string hash);
void unset_hash();
string
-dcp::make_digest (boost::filesystem::path filename, function<void (float)> progress)
+dcp::make_digest(boost::filesystem::path filename, function<void (int64_t, int64_t)> progress)
{
Kumu::FileReader reader;
auto r = reader.OpenRead(dcp::filesystem::fix_long_path(filename).string().c_str());
SHA1_Update (&sha, read_buffer.Data(), read);
if (progress) {
- progress (float (done) / size);
+ progress(done, size);
done += read;
}
}
/** Create a digest for a file
* @param filename File name
- * @param progress Optional progress reporting function. The function will be called
- * with a progress value between 0 and 1
+ * @param progress Optional progress reporting function, called with a number of bytes done
+ * and a total number of bytes.
* @return Digest
*/
-extern std::string make_digest (boost::filesystem::path filename, boost::function<void (float)>);
+extern std::string make_digest(boost::filesystem::path filename, boost::function<void (int64_t, int64_t)>);
extern std::string make_digest (ArrayData data);
* call to hash().
*/
reel_file_asset->asset_ref()->unset_hash();
- auto const actual_hash = reel_file_asset->asset_ref()->hash(progress);
+ auto const actual_hash = reel_file_asset->asset_ref()->hash([progress](int64_t done, int64_t total) {
+ progress(float(done) / total);
+ });
auto pkls = dcp->pkls();
/* We've read this DCP in so it must have at least one PKL */
}
-void progress (float f)
-{
- cout << (f * 100) << "% \r";
-}
-
-
int
main (int argc, char* argv[])
{
auto asset = dcp::asset_factory(i.path(), true);
asset->set_file (*output / i.path().filename());
cout << "Hashing " << i.path().filename() << "\n";
- asset->hash (&progress);
+ asset->hash([](int64_t done, int64_t size) {
+ cout << (float(done) * 100 / size) << "% \r";
+ });
cout << "100% \n";
assets.push_back (asset);
} catch (dcp::ReadError& e) {