Computed file's md5 by webAssembly

Overview

wasm-md5

computed file's md5 by webAssembly

How to install

npm install @fuyoo/wasm-md5

How to use

MD5 WASM
">
>
<html>

<head>
    <meta charset="UTF-8">
    <title>MD5 WASMtitle>
head>

<body>
<button id="file">选择文件button>
<div id="fileinfo">div>
<div id="progress">div>
<div id="time">div>
body>
<script src="index.js">script>
html>
{ let start = Date.now() pkg.hash(file, (ps) => { progress.innerHTML = `MD5计算中:已完成${(ps / 1.0).toFixed(2)}%` }).then(res => { progress.innerHTML = `MD5计算已完成` time.innerHTML = `MD5: ${res}, 用时${(Date.now() - start) / 1000}s` }) }) } i.click() function reset() { progress.innerHTML = "" fileinfo.innerHTML = "" time.innerHTML = "" } function getSize(size) { if (size < cf(1)) return size + "Bytes" if (size >= cf(1) && size < cf(2)) return (size / cf(1)).toFixed(3) + "Kb" if (size >= cf(2) && size < cf(3)) return (size / cf(2)).toFixed(3) + "Mb" if (size >= cf(3) && size < cf(4)) return (size / cf(3)).toFixed(3) + "Gb" if (size >= cf(4) && size < cf(5)) return (size / cf(4)).toFixed(3) + "Tb" return (size / cf(1)).toFixed(3) + "Kb" } function cf(n) { let r = 1024 for (let i = 1; i < n; i++) { r *= 1024 } return r } }) ">
document.querySelector("#file")
    .addEventListener("click", function () {
        let progress = document.querySelector("#progress")
        let fileinfo = document.querySelector("#fileinfo")
        let time = document.querySelector("#time")
        let i = document.createElement("input")
        i.type = "file"
        i.onchange = function () {
            reset()
            let file = (this.files[0])
            fileinfo.innerHTML = `文件名:${file.name} 共:${getSize(file.size)}`
            import ("@fuyoo/md5-wasm")
                .then(pkg => {
                    let start = Date.now()
                    pkg.hash(file, (ps) => {
                        progress.innerHTML = `MD5计算中:已完成${(ps / 1.0).toFixed(2)}%`
                    }).then(res => {
                        progress.innerHTML = `MD5计算已完成`
                        time.innerHTML = `MD5: ${res}, 用时${(Date.now() - start) / 1000}s`
                    })
                })
        }
        i.click()

        function reset() {
            progress.innerHTML = ""
            fileinfo.innerHTML = ""
            time.innerHTML = ""
        }

        function getSize(size) {
            if (size < cf(1)) return size + "Bytes"
            if (size >= cf(1) && size < cf(2)) return (size / cf(1)).toFixed(3) + "Kb"
            if (size >= cf(2) && size < cf(3)) return (size / cf(2)).toFixed(3) + "Mb"
            if (size >= cf(3) && size < cf(4)) return (size / cf(3)).toFixed(3) + "Gb"
            if (size >= cf(4) && size < cf(5)) return (size / cf(4)).toFixed(3) + "Tb"
            return (size / cf(1)).toFixed(3) + "Kb"

        }

        function cf(n) {
            let r = 1024
            for (let i = 1; i < n; i++) {
                r *= 1024
            }
            return r
        }
    })

license

MIT LICENSE

You might also like...
WebAssembly development with Trunk & Vite.js

Trunk & Vite.js Demo Trunk is a WASM web application bundler for Rust, and Vite.js is next Generation Frontend Tooling. Ok, they are together now for

darkforest is a console and web-based Roguelike written in Rust and WebAssembly.
darkforest is a console and web-based Roguelike written in Rust and WebAssembly.

darkforest darkforest is a console and web-based Roguelike written in Rust and WebAssembly. Key Features TBA Quick Start TBA How To Contribute Contrib

WebAssembly to Lua translator, with runtime

This is a WIP (read: absolutely not ready for serious work) tool for translating WebAssembly into Lua. Support is specifically for LuaJIT, with the se

A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly
A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly

ESP Stack Trace Decoder A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly. It is composed of a ⌨️ Rust library,

Simple file sharing with client-side encryption, powered by Rust and WebAssembly
Simple file sharing with client-side encryption, powered by Rust and WebAssembly

Hako Simple file sharing with client-side encryption, powered by Rust and WebAssembly Not feature-packed, but basic functionalities are just working.

bn.js bindings for Rust & WebAssembly with primitive-types support

bn.rs bn.js bindings for Rust & WebAssembly with primitive-types support Write Rust code that uses BN use std::str::FromStr; use primitive_types::{H1

A handy calculator, based on Rust and WebAssembly.
A handy calculator, based on Rust and WebAssembly.

qubit 💥 Visit Website To Use Calculator Example 💥 Visit Website To Use Calculator 2 + 2

A simple compile-to-WebAssembly language rewritten in Rust

chasm A very simple compile-to-WebAssembly language You can play with chasm online. This is a rewrite in Rust of the compiler for the language chasm.

Webassembly binding for Hora Approximate Nearest Neighbor Search Library
Webassembly binding for Hora Approximate Nearest Neighbor Search Library

hora-wasm [Homepage] [Document] [Examples] [Hora] Javascript bidding for the Hora Approximate Nearest Neighbor Search, in WebAssembly way. Features Pe

Owner
fuyoo
start by hello world, over off by hello world!
fuyoo
Rust-based WebAssembly bindings to read and write Apache Parquet files

parquet-wasm WebAssembly bindings to read and write the Parquet format to Apache Arrow. This is designed to be used alongside a JavaScript Arrow imple

Kyle Barron 103 Dec 25, 2022
Contains the source code to compile the drop'in language into WebAssembly files

drop'in compiler This repository contains the source code to compile the drop'in language into WebAssembly files. This source code is in an experiment

Blue Forest 2 Dec 17, 2022
A prototype WebAssembly linker using module linking.

WebAssembly Module Linker Please note: this is an experimental project. wasmlink is a prototype WebAssembly module linker that can link together a mod

Peter Huene 19 Oct 28, 2022
Sealed boxes implementation for Rust/WebAssembly.

Sealed boxes for Rust/WebAssembly This Rust crate provides libsodium sealed boxes for WebAssembly. Usage: // Recipient: create a new key pair let reci

Frank Denis 16 Aug 28, 2022
WebAssembly on Rust is a bright future in making application runs at the Edge or on the Serverless technologies.

WebAssembly Tour WebAssembly on Rust is a bright future in making application runs at the Edge or on the Serverless technologies. We spend a lot of ti

Thang Chung 129 Dec 28, 2022
WebAssembly modules that use Azure services

This is an experimental repository containing WebAssembly modules running on top of WAGI (WebAssembly Gateway Interface, which allows you to run WebAssembly WASI binaries as HTTP handlers) and using Azure services.

null 7 Apr 18, 2022
WebAssembly Service Porter

WebAssembly Service Porter.

henrylee2cn 12 Dec 12, 2022
🚀Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere

Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere: from Desktop to the Cloud, Edge and IoT devices.

Wasmer 14.1k Jan 8, 2023
WAGI: WebAssembly Gateway Interface

Write HTTP handlers in WebAssembly with a minimal amount of work

null 724 Jan 6, 2023
A console and web-based Gomoku written in Rust and WebAssembly

?? rust-gomoku A console and web-based Gomoku written in Rust and WebAssembly Getting started with cargo & npm Install required program, run # install

namkyu1999 2 Jan 4, 2022