Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file2md5

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file2md5

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

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
198
decreased by-22.66%
Maintainers
1
Weekly downloads
 
Created
Source

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

NameRequiredDescriptionTypeDefault value
filetrueThe file is used to convert md5 format.File-
optionsfalseOptional configuration items.IOptions{}

Options

NameRequiredDescriptionTypeDefault value
chunkSizefalseThe conversion is performed in chunks, so you can customize the size of each chunk.number2 * 1024 * 1024
rawfalseIf raw is true, the result as a binary string will be returned instead.booleanfalse
onProgressfalseCallback 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

FAQs

Package last updated on 10 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc