Asset::digest () const
{
if (_digest.empty ()) {
- _digest = make_digest (path().string());
+ _digest = make_digest (path().string(), 0);
}
return _digest;
}
+void
+Asset::compute_digest (boost::function<void (float)> progress)
+{
+ if (!_digest.empty ()) {
+ return;
+ }
+
+ _digest = make_digest (path().string(), &progress);
+}
+
bool
Asset::equals (shared_ptr<const Asset> other, EqualityOptions, boost::function<void (NoteType, string)> note) const
{
*/
void write_to_assetmap (xmlpp::Node *) const;
+ /** Compute the digest for this asset. Calling this is optional: if
+ * it is not called, the digest will be computed when required. However,
+ * calling this method allows the caller to see the progress of the
+ * computation, which can be long for large assets.
+ * @param Called with progress between 0 and 1.
+ */
+ void compute_digest (boost::function<void (float)> progress);
+
std::string uuid () const {
return _uuid;
}
doc.write_to_file_formatted (p.string (), "UTF-8");
- _digest = make_digest (p.string ());
+ _digest = make_digest (p.string (), 0);
_length = boost::filesystem::file_size (p.string ());
}
/** Create a digest for a file.
* @param filename File name.
+ * @param progress Pointer to a progress reporting function, or 0. The function will be called
+ * with a progress value between 0 and 1.
* @return Digest.
*/
string
-libdcp::make_digest (string filename)
+libdcp::make_digest (string filename, boost::function<void (float)>* progress)
{
Kumu::FileReader reader;
if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) {
SHA_CTX sha;
SHA1_Init (&sha);
-
- Kumu::ByteString read_buffer (65536);
+
+ int const buffer_size = 65536;
+ Kumu::ByteString read_buffer (buffer_size);
+
+ Kumu::fsize_t done = 0;
+ Kumu::fsize_t const size = reader.Size ();
while (1) {
ui32_t read = 0;
Kumu::Result_t r = reader.Read (read_buffer.Data(), read_buffer.Capacity(), &read);
}
SHA1_Update (&sha, read_buffer.Data(), read);
+
+ if (progress) {
+ (*progress) (float (done) / size);
+ done += read;
+ }
}
byte_t byte_buffer[20];
#include <string>
#include <stdint.h>
#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
#include <openjpeg.h>
#include "types.h"
extern bool operator!= (Size const & a, Size const & b);
extern std::string make_uuid ();
-extern std::string make_digest (std::string filename);
+extern std::string make_digest (std::string filename, boost::function<void (float)> *);
extern std::string content_kind_to_string (ContentKind kind);
extern ContentKind content_kind_from_string (std::string kind);
extern bool empty_or_white_space (std::string s);