Coder Social home page Coder Social logo

bdwenxi / file2md5 Goto Github PK

View Code? Open in Web Editor NEW
110.0 9.0 18.0 400 KB

file2md5 is a browser-side implementation of file conversion to md5 format based on SparkMD5, which supports typescript friendly.

License: MIT License

TypeScript 87.27% JavaScript 12.73%

file2md5's Introduction

file2md5

Commitizen friendly GitHub license GitHub release

file2md5 is a browser-side implementation of file conversion to md5 format based on SparkMD5, which supports typescript friendly.

Features

  • Supports Typescript

  • Promise API

  • All browsers supported

Installation

Npm

npm install file2md5 --save

Yarn

yarn add file2md5

Usage

Html:

<input type="file" id="upload" />

Javascript:

import file2md5 from 'file2md5';

const el = document.querySelector('#upload');
const onProgress = progress => console.log('progress', progress);

const onChange = async e => {
    if (!e.target.files || !e.target.files[0]) {
        return;
    }

    const file = e.target.files[0];
    const abort = file2md5.abort;

    // Assuming that it takes 3s to convert the md5 value,
    // the simulation terminates the operation at 1s
    setTimeout(
        () => abort(),
        1000
    );

    try {
        const md5 = await file2md5(file, {chunkSize: 3 * 1024 * 1024, onProgress});
        console.log('md5 string:', md5); // d18bb890790c4335e57eadbedc801c2c
    }
    catch (e) {
        console.error('error', e);
    }
};

el.addEventListener(
    'change',
    onChange,
    false
);

You can call the abort method to terminate before the end of the file conversion to the md5 value.

const abort = file2md5.abort;

abort();

Params

Name Required Description Type Default value
file true The file is used to convert md5 format. File -
options false Optional configuration items. IOptions {}

Options

Name Required Description Type Default value
chunkSize false The conversion is performed in chunks, so you can customize the size of each chunk. number 2 * 1024 * 1024
raw false If raw is true, the result as a binary string will be returned instead. boolean false
onProgress false Callback function for monitoring progress. (progress: number) => unknown -

Browser compatibility

  • IE10+
  • Chrome latest 2 versions
  • Firefox latest 2 versions
  • Microsoft Edge latest 2 versions
  • Safari latest 2 versions

License

file2md5 is licensed under a MIT License

file2md5's People

Contributors

bdwenxi avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

file2md5's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
npm
package.json
  • spark-md5 ^3.0.1
  • @types/jest 29.4.4
  • @types/lodash.noop 3.0.7
  • @types/spark-md5 3.0.2
  • cz-conventional-changelog 3.3.0
  • husky 8.0.3
  • reskript 0.26.7
  • typescript 4.9.5

  • Check this box to trigger a request for Renovate to run again on this repository

ie下无法引用

大佬可以生成一份es5的代码更新下npm包吗,现在ie下不能用😭

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.