Learn R Programming

rdrop2 (version 0.8.2.1)

drop_content_hash: Compute Dropbox's content hash for one or more files

Description

Compute a "content hash" using the same algorithm as dropbox. This can be used to verify the content against the content_hash field returned in drop_dir.

Usage

drop_content_hash(file)

Arguments

file

A vector of filenames

Value

A character vector the same length as file. Each element is 64 character string which is the unique hash. Two files that have the same hash have the same contents. Compare this hash of a local file with the content_hash field from drop_dir to see if you have the same file as dropbox.

Details

Dropbox returns a hash of file contents in drop_dir. However, this is not a straightforward file hash. Instead the file is divided into 4MB chunks, each of those is hashed and then the concatenation of the hashes is itself hashed (see this page in the dropbox developer documentation for the details). It's entirely unclear why it does not compute a hash of the file itself, but here we are.

Examples

Run this code
# NOT RUN {
write.csv(mtcars, file = "mtt.csv")
drop_upload("mtt.csv")
files <- drop_dir()
# Dropbox's reported hash
files$content_hash[files$name == "mtt.csv"]
# Our computed hash:
drop_content_hash("mtt.csv")
# }

Run the code above in your browser using DataLab