A lightweight, zero-dependency JavaScript library for MD5 hashing with streaming support for large files.
npm install pure-md5
# or
yarn add pure-md5
# or
pnpm add pure-md5import { md5 } from 'pure-md5/md5';
const hash = md5('hello');
console.log(hash); // "5d41402abc4b2a76b9719d911017c592"import { createMD5Stream } from 'pure-md5';
import fs from 'fs';
const stream = createMD5Stream();
stream.on('md5', result => console.log('MD5:', result.digest));
fs.createReadStream('large-file.bin').pipe(stream);- β‘ Zero Dependencies - No external dependencies, ever
- π¦ Tiny Bundle - ~1.4KB gzipped for md5() only (with tree-shaking), ~6KB for full bundle
- π― Multiple APIs - Simple, streaming, and promise-based
- π¦Ί TypeScript Ready - Full type definitions included
- π Adapter System - Automatic detection (WebCrypto, Node.js, Pure JS)
- π File Hashing - Stream large files with progress tracking
- π Universal - Works in Node.js and browsers
- API Reference
- Streaming API
- Streaming Examples
- Migration Guide
- Troubleshooting
- Benchmarks
- Contributing
Compute MD5 hash of a string or buffer.
import { md5 } from 'pure-md5/md5'; // Tree-shakeable, ~1.4KB
const hash = md5('hello');
console.log(hash); // "5d41402abc4b2a76b9719d911017c592"Create a new MD5Stream instance.
import { createMD5Stream } from 'pure-md5';
const stream = createMD5Stream();
stream.on('md5', result => {
console.log('MD5:', result.digest); // "5d41402abc4b2a76b9719d911017c592"
console.log('Bytes:', result.bytesProcessed); // 5
});Pipe a stream through MD5 hashing and get a promise.
import { pipeThroughMD5, fromReadable } from 'pure-md5';
const source = fromReadable(['hello', ' ', 'world']);
const result = await pipeThroughMD5(source);
console.log('MD5:', result.digest);Convenience method to create a stream and get result.
import { fromStream } from 'pure-md5';
import fs from 'fs';
const { stream, result } = fromStream(fs.createReadStream('file.txt'));
result.then(r => console.log('MD5:', r.digest));Hash a file asynchronously.
import { hashFile } from 'pure-md5';
const result = await hashFile('path/to/file.txt');
console.log('MD5:', result.digest);
console.log('Bytes:', result.bytesProcessed);
// With progress tracking
const progress = createProgressTracker(result.bytesProcessed, percent => {
console.log(`Progress: ${percent.toFixed(1)}%`);
});
const result = await hashFile('large-file.bin', { onProgress: progress });Hash a file and return only the digest.
import { hashFileDigest } from 'pure-md5';
const digest = await hashFileDigest('path/to/file.txt');
console.log('MD5:', digest);Hash a file synchronously (for small files).
import { hashFileSync } from 'pure-md5';
const digest = hashFileSync('small-file.txt');
console.log('MD5:', digest);Verify file integrity using MD5.
import { verifyFile } from 'pure-md5';
const isVerified = await verifyFile('path/to/file.txt', '5d41402abc4b2a76b9719d911017c592');
console.log('Verified:', isVerified); // true or false<script src="https://unpkg.com/pure-md5@latest/dist/index.js"></script>
<script>
console.log(md5('hello')); // "5d41402abc4b2a76b9719d911017c592"
</script>| Feature | pure-md5 | pvorb/node-md5 | crypto-js | js-md4 | Node.js crypto |
|---|---|---|---|---|---|
| Bundle Size (md5 only) | ~1.4KBΒΉ | ~3KB | ~4KB | ~2KB | N/A |
| Bundle Size (full) | ~6KBΒΉ | ~3KB | ~4KB | ~2KB | N/A |
| Dependencies | 0 | 0 | 0 | 0 | 0 |
| Streaming | β | β | β | β | β |
| Browser Support | β | β | β | β | β |
| TypeScript | β | β | β | β | |
| Zero Config | β | βΒ² | β | β | β |
| Tree-shaking | β | β | β | β | N/A |
| Pure JS (no Node) | β | β | β | β | β |
ΒΉ With tree-shaking: Only import what you use!
Β² Requires Node.js environment - not browser-compatible
- Browser Support: pvorb/node-md5 only works in Node.js, while pure-md5 works everywhere
- Tree-shaking: pure-md5 supports modern tree-shaking for smaller bundles
- Streaming: built-in streaming API for large files in pure-md5
- TypeScript: first-class TypeScript support with full type definitions
- Zero dependencies: truly zero-dependency implementation
- Modern API: cleaner, more intuitive interface with promise-based options
pvorb/node-md5 is still a good choice if you only need Node.js and prefer its API style.
// Node.js adapter is auto-detected
import { md5 } from 'pure-md5';// WebCrypto adapter is auto-detected
import { md5 } from 'pure-md5';Use adapter backends directly when you need explicit control:
import { NodeCryptoBackend, WebCryptoBackend, PureJSBackend } from 'pure-md5';
// Create backend instances
const nodeBackend = new NodeCryptoBackend();
const hash = await nodeBackend.hash('hello');
console.log(hash);Contributions are welcome! Please read our Contributing Guide for details.
git clone https://github.com/eustatos/pure-md5.git
cd pure-md5
npm install
npm testnpm test # Run all tests
npm run coverage # Generate coverage report
npm run build:watch # Build in watch modeThis project is licensed under the MIT License - see the LICENSE.md file for details.
If you find this project helpful, please consider supporting it:
- β Star this repository
- π¦ Tweet about it
- π¬ Share with your community
- πΊ Buy me a coffee (coming soon)
*Made with β€οΈ by Aleksandr Astashkin