# pure-md5

> A lightweight JavaScript function for hashing messages by the MD5 algorithm

Latest version **1.0.0** (published 2026-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install pure-md5
pnpm add pure-md5
yarn add pure-md5
bun add pure-md5
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-07-10 |
| First published | 2019-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 158.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Aleksandr Astashkin |
| Maintainers | eustatos |
| Keywords | md5, hash, checksum, digest, crypto, streaming, file-hash, integrity, browser, typescript, zero-dependency, lightweight |

## Links

- npm: https://www.npmjs.com/package/pure-md5
- Repository: https://github.com/eustatos/pure-md5
- Issues: https://github.com/eustatos/pure-md5/issues
- npm.io page: https://npm.io/package/pure-md5

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2026-07-10
- 0.2.5 — 2026-06-26
- 0.2.4 — 2026-03-27
- 0.2.3 — 2026-03-27
- 0.2.2 — 2026-02-21
- 0.2.1 — 2026-02-21
- 0.2.0 — 2026-02-17
- 0.1.14 — 2022-06-21
- 0.1.13 — 2020-07-10
- 0.1.12 — 2020-07-10
- 0.1.10 — 2020-07-10
- 0.1.9 — 2019-06-19
- 0.1.8 — 2019-06-19
- 0.1.7 — 2019-06-19
- 0.1.6 — 2019-06-19
- … 6 more at https://npm.io/package/pure-md5/versions

## README

# pure-md5

**A lightweight, zero-dependency MD5 hashing library for Node.js and browsers.**

[![npm version](https://img.shields.io/npm/v/pure-md5.svg?style=flat&color=informational)](https://npmjs.org/package/pure-md5)
[![npm downloads](https://img.shields.io/npm/dw/pure-md5.svg?style=flat&color=blue)](https://npmjs.org/package/pure-md5)
[![Coverage Status](https://coveralls.io/repos/github/eustatos/pure-md5/badge.svg?branch=master)](https://coveralls.io/github/eustatos/pure-md5?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

---

## Install

```bash
npm install pure-md5
```

## Quick Start

```javascript
import { md5 } from 'pure-md5';

md5('hello'); // "5d41402abc4b2a76b9719d911017c592"
```

For the smallest possible bundle, import from the minimal entry:

```javascript
import { md5 } from 'pure-md5/md5'; // ~1.5 KB gzipped
```

## Streaming & File Hashing

```javascript
import { hashFile, createMD5Stream } from 'pure-md5/stream';

// Hash a file
const result = await hashFile('large-file.bin');
console.log(result.digest); // "abc123..."

// Stream API
import fs from 'fs';
const stream = createMD5Stream();
stream.on('md5', r => console.log('MD5:', r.digest));
fs.createReadStream('large-file.bin').pipe(stream);
```

## Binary Data

```javascript
import { md5Buffer } from 'pure-md5';

const data = new Uint8Array([0x00, 0xFF, 0x80]);
md5Buffer(data); // correct hash for raw bytes
```

---

## Features

- **Zero dependencies** — no external packages, ever
- **~1.5 KB gzipped** for `md5()` (tree-shakeable)
- **Streaming** — hash multi-GB files without loading into memory
- **TypeScript** — full type definitions included
- **Universal** — works in Node.js and browsers
- **Binary-safe** — correct hashes for non-UTF-8 byte data

---

## API

### `md5(message: string): string`

Compute MD5 hash of a string (UTF-8 encoded).

```javascript
import { md5 } from 'pure-md5';
md5('hello'); // "5d41402abc4b2a76b9719d911017c592"
```

### `md5Buffer(data: Uint8Array | ArrayBuffer): string`

Compute MD5 hash of binary data.

```javascript
import { md5Buffer } from 'pure-md5';
md5Buffer(new Uint8Array([104, 101, 108, 108, 111])); // "5d41402abc4b2a76b9719d911017c592"
```

### `md5Async(message: string): Promise<string>`

Async wrapper with automatic backend selection.

```javascript
import { md5Async } from 'pure-md5';
await md5Async('hello'); // "5d41402abc4b2a76b9719d911017c592"
```

### Streaming API (`pure-md5/stream`)

| Function | Description |
|----------|-------------|
| `hashFile(path, options?)` | Hash a file asynchronously with optional progress |
| `hashFileDigest(path)` | Hash a file, return digest only |
| `hashFileSync(path)` | Synchronous file hash (small files) |
| `verifyFile(path, expected)` | Verify file integrity |
| `createMD5Stream()` | Create a Node.js Transform stream |
| `pipeThroughMD5(source)` | Pipe a stream through MD5, get a promise |
| `fromStream(stream)` | Create stream + result promise pair |
| `createProgressTracker(total, cb)` | Progress callback helper |

```javascript
import { hashFile, createProgressTracker } from 'pure-md5/stream';

const result = await hashFile('video.mp4', {
  onProgress: createProgressTracker(fileSize, pct => console.log(`${pct}%`))
});
```

### WHATWG Streams (Browser)

```javascript
import { MD5ReadableStream, hashBlob } from 'pure-md5/stream';

// Hash a Blob
const digest = await hashBlob(fileBlob);

// Hash a ReadableStream
const result = await MD5ReadableStream.hash(readableStream);
```

### Backend Adapters

```javascript
import { NodeCryptoBackend, BrowserBackend, PureJSBackend } from 'pure-md5';

const backend = new NodeCryptoBackend();
await backend.hash('hello');
```

Use `pure-md5/detect` for backend detection and fallback utilities.

---

## Comparison

| Feature | pure-md5 | js-md5 | crypto-js | node-md5 | Node crypto |
|---------|----------|--------|-----------|----------|-------------|
| MD5 only size | ~1.5 KB¹ | ~3 KB | ~68 KB² | ~3 KB | N/A |
| Dependencies | 0 | 0 | 0 | 0 | 0 |
| Streaming | ✅ | ❌ | ❌ | ❌ | ✅ |
| Browser | ✅ | ✅ | ✅ | ❌ | ❌ |
| TypeScript | ✅ | ⚠️ | ❌ | ❌ | ❌ |
| Binary-safe | ✅ | ✅ | ✅ | ✅ | ✅ |
| Tree-shaking | ✅ | ❌ | ❌ | ❌ | N/A |

¹ With `import { md5 } from 'pure-md5/md5'`
² crypto-js is a monolithic bundle

---

## CDN

```html
<script type="module">
  import { md5 } from 'https://esm.sh/pure-md5';
  console.log(md5('hello'));
</script>
```

---

## Documentation

- [Streaming API](STREAM_API.md)
- [Streaming Examples](STREAM_EXAMPLES.md)
- [Migration Guide](MIGRATION_GUIDE_STREAMS.md)
- [Troubleshooting](STREAM_TROUBLESHOOTING.md)

---

## Contributing

See [Contributing Guide](CONTRIBUTING.md).

```bash
git clone https://github.com/eustatos/pure-md5.git
cd pure-md5
npm install
npm test
```

## License

MIT — see [LICENSE.md](LICENSE.md).

---
_Source: https://npm.io/package/pure-md5 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
