Coder Social home page Coder Social logo

md5-file's Introduction

MD5 file

Get the MD5-sum of a given file, with low memory usage, even on huge files.

Installation

npm install --save md5-file

Usage

As a module

const md5File = require('md5-file')

/* Async usage */
md5File('LICENSE.md').then((hash) => {
  console.log(`The MD5 sum of LICENSE.md is: ${hash}`)
})

/* Sync usage */
const hash = md5File.sync('LICENSE.md')
console.log(`The MD5 sum of LICENSE.md is: ${hash}`)

As a command line tool

$ md5-file LICENSE.md
ad1faf9381e43c471dc381c17a4ee4b6

API

md5File(path: string) => Promise<string>

Asynchronously get the MD5-sum of the file at path.

Returns a Promise that will be resolved with a string containing the MD5-sum.

md5File.sync(path: string) => string

Synchronously get the MD5-sum of the file at path.

License

MIT

md5-file's People

Contributors

bambutz avatar kodie avatar linusu avatar realityking avatar richienb avatar roryrjb 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

md5-file's Issues

Async version is slow

It seems async version is slower than it needs to be. I haven't compares it with sync version because I'm using async one in multiple concurrent operations. They seem to be a lot slower than they need to be.

I notice that in sync version the file is only read upto a certain BUFFER_SIZE. This seems not to be the case in async version - it seems to read the whole file. Could that be the cause?

Looking for new maintainer

I don't use this module anymore, and to be honest I don't even use Node.js or GitHub much anymore, and I don't have the time to update it, review issues or pull requests, so I am looking for a new maintainer. I won't just pick anyone, as people are using the module, so I have to ensure it goes into good hands. If no one suitable comes forward (in a reasonable amount of time) I will deprecate the module in npm and archive the repo in GitHub.

promise.js file is not included in module

Hello,

I installed the package with npm install --save md5-file and got ^3.1.0, but the promise.js file is not included, so require('md5-file/promise') does not work.

You can use pipe

You can .pipe the fileStream directly to the hash instead of using update.

fileStream.pipe(sum)

Breaking change between 4.0.0 and 5.0.0

Using md5-file to md5 files with a callback on 4.0.0 works as below:

md5File(filename, (err, hash) => {
   console.log("starting hash on " + filename);
   if (err) {
      console.log(err);
   } else {
      console.log(hash);
   }
});

On 5.0.0, this no longer works, the code within the callback is never executed.

Change api to have two separate functions

I think it would be nicer if the api looked like this:

// Async
md5File('LICENSE.md', (err, hash) => {})

// Sync
md5File.sync('LICENSE.md')

This seems to be where the community landed, and there are a lot of high profile packages (see below) following this style. By following this style, we adhere to the Principle_of_least_astonishment.

It would also allow us to have more strict arguments validation ๐Ÿ™Œ

Support modern browser runtime?

Hi Rory and Linus,

Thanks for this great repo!

I am wondering whether you would like to add modern browser support? Maybe utilising FileReader API to handle fs work?

It would be great to see that happen. I can contribute with some PR too :)

Best,
Blake

doesn't work with files > 1GB

Thanks for making this package. It was useful to get me started.

FYI, using fs.readFile doesn't work for > 1 GB files since it reads the entire contents of the file into memory and the max buffer size is 1 GB.

This can work using a streaming approach such as discussed here:

http://stackoverflow.com/questions/18658612/obtaining-the-hash-of-a-file-using-the-stream-capabilities-of-crypto-module-ie

I used createReadStream piped to a hash object successfully to get the MD5 hash of 2GB files.
Of course it's not for a security context, simply a convenience for a download check.

Thanks again for your contributions to the community.

Reverse Process

Hey,so i was wandering if there is a way to convert the generated hash back to the file again.
Can the process be reversed? :)

Not working on windows

Not working in windows.

But after commenting the first line which is #!/usr/bin/env node of the node_modules\md5-file\index.js it works fine.

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.