Skip to content

Commit f80dbe3

Browse files
committed
Move the get_sha1sum function to utils.rs
1 parent a9895bf commit f80dbe3

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::ffi::OsString;
77

88
use libflate::gzip;
99
use tar;
10+
use sha1::Sha1;
1011

1112
#[derive(Debug)]
1213
pub struct ExecutionStatus {
@@ -94,3 +95,20 @@ pub fn unpack< I: AsRef< Path >, O: AsRef< Path > >( input_path: I, output_path:
9495

9596
Ok(())
9697
}
98+
99+
pub fn get_sha1sum< P: AsRef< Path > >( path: P ) -> io::Result< String > {
100+
let path = path.as_ref();
101+
let mut fp = File::open( path )?;
102+
let mut hasher = Sha1::new();
103+
104+
let mut buffer = Vec::new();
105+
buffer.resize( 1024 * 1024, 0 );
106+
loop {
107+
match fp.read( &mut buffer )? {
108+
0 => break,
109+
count => hasher.update( &buffer[ 0..count ] )
110+
}
111+
}
112+
113+
Ok( format!( "{}", hasher.digest() ) )
114+
}

src/wasm.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::path::{Path, PathBuf};
22
use std::fs::{self, File};
33
use std::io::{self, Read, Write};
44

5-
use sha1::Sha1;
65
use parity_wasm;
76
use cargo_shim::BuildConfig;
87
use serde_json;
@@ -18,29 +17,13 @@ use wasm_intrinsics;
1817
use wasm_runtime::{self, RuntimeKind};
1918
use wasm_js_export;
2019
use wasm_js_snippet;
20+
use utils::get_sha1sum;
2121

2222
#[derive(Serialize, Deserialize)]
2323
struct Metadata {
2424
wasm_hash: String
2525
}
2626

27-
fn get_sha1sum< P: AsRef< Path > >( path: P ) -> io::Result< String > {
28-
let path = path.as_ref();
29-
let mut fp = File::open( path )?;
30-
let mut hasher = Sha1::new();
31-
32-
let mut buffer = Vec::new();
33-
buffer.resize( 1024 * 1024, 0 );
34-
loop {
35-
match fp.read( &mut buffer )? {
36-
0 => break,
37-
count => hasher.update( &buffer[ 0..count ] )
38-
}
39-
}
40-
41-
Ok( format!( "{}", hasher.digest() ) )
42-
}
43-
4427
pub fn process_wasm_file< P: AsRef< Path > + ?Sized >( uses_old_stdweb: bool, runtime: RuntimeKind, build: &BuildConfig, prepend_js: &str, target_dir: &Path, artifact: &P ) -> Option< PathBuf > {
4528
if !build.triplet.as_ref().map( |triplet| triplet == "wasm32-unknown-unknown" ).unwrap_or( false ) {
4629
return None;

0 commit comments

Comments
 (0)