Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
use twox_hash for asset manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Apr 22, 2020
1 parent 017466b commit 004fb92
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
24 changes: 10 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ clap = "2.32.0"
cloudflare = "0.6.4"
config = "0.10.1"
console = "0.9.1"
data-encoding = "2.1.2"
dirs = "1.0.5"
env_logger = "0.6.1"
exitfailure = "0.5.1"
Expand Down Expand Up @@ -49,7 +48,6 @@ reqwest = { version = "0.10.1", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.39"
serde_with = "1.3.1"
sha2 = "0.8.0"
tempfile = "3.1.0"
term_size = "0.3"
text_io = "0.1.7"
Expand All @@ -60,6 +58,7 @@ url = "2.1.0"
uuid = { version = "0.8", features = ["v4"] }
which = "2.0.1"
ws = "0.9.0"
twox-hash = "1.5.0"

[dev-dependencies]
assert_cmd = "0.11.1"
Expand Down
15 changes: 7 additions & 8 deletions src/commands/kv/bucket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ pub use upload::upload_files;

use std::ffi::OsString;
use std::fs;
use std::hash::Hasher;
use std::path::Path;

use data_encoding::HEXLOWER;
use failure::format_err;
use ignore::overrides::{Override, OverrideBuilder};
use ignore::{Walk, WalkBuilder};
use indicatif::{ProgressBar, ProgressStyle};
use sha2::{Digest, Sha256};
use twox_hash::XxHash64;

use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair;

Expand Down Expand Up @@ -197,7 +197,6 @@ pub fn generate_path_and_key(
let relative_path = path.strip_prefix(directory).unwrap();

let url_safe_path = generate_url_safe_path(relative_path)?;

let path_with_hash = if let Some(value) = value {
let digest = get_digest(value)?;

Expand All @@ -210,11 +209,11 @@ pub fn generate_path_and_key(
}

fn get_digest(value: String) -> Result<String, failure::Error> {
let mut hasher = Sha256::new();
hasher.input(value);
let digest = hasher.result();
let hex_digest = HEXLOWER.encode(digest.as_ref())[0..10].to_string();
Ok(hex_digest)
let value = value.as_bytes();
let mut hasher = XxHash64::default();
hasher.write(value);
let digest = hasher.finish();
Ok(digest.to_string())
}

// Assumes that `path` is a file (called from a match branch for path.is_file())
Expand Down
1 change: 0 additions & 1 deletion src/commands/kv/bucket/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn upload_files(
} else {
None
};

while !(pairs.is_empty() && key_value_batch.is_empty()) {
if pairs.is_empty() {
// Last batch to upload
Expand Down

0 comments on commit 004fb92

Please sign in to comment.