# @tomasklaen/checksum

> Checksum strings, buffers, streams, or file paths.

Latest version **1.1.0** (published 2021-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tomasklaen/checksum
pnpm add @tomasklaen/checksum
yarn add @tomasklaen/checksum
bun add @tomasklaen/checksum
```

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-12-23 |
| First published | 2021-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | tomasklaen |
| Maintainers | tomasklaen |
| Keywords | checksum, file, string, buffer, stream, crc32, md5, sha1, sha256, sha512 |

## Links

- npm: https://www.npmjs.com/package/@tomasklaen/checksum
- Repository: https://github.com/tomasklaen/checksum
- Issues: https://github.com/tomasklaen/checksum/issues
- npm.io page: https://npm.io/package/@tomasklaen/checksum

## Dependencies (1)

- [crc32-stream](https://npm.io/package/crc32-stream.md) ^4.0.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-12-23
- 1.0.1 — 2021-12-04
- 1.0.0 — 2021-12-04

## README

# @tomasklaen/checksum

A utility to checksum a string, buffer, readable stream, or a file at provided path.

Supports `crc32` and all algorithms supported by `crypto.createHash(algorithmName)` of the current Node.js process.

Run this to find out exactly what algorithms are available in your environment:

```
node -e "console.log(crypto.getHashes())"
```

These _should_ be available everywhere: `md5`, `sha1`, `sha256`, `sha512`

## Install

```
npm install @tomasklaen/checksum
```

## Usage

CommonJS:

```js
const {checksum, checksumFile} = require('@tomasklaen/checksum');
```

ES modules:

```ts
import {checksum, checksumFile} from '@tomasklaen/checksum';

await checksum('foo', 'crc32'); // '8c736521'
await checksumFile('/path/to/foo.txt', 'crc32'); // '8c736521'
```

## API

Everything exported by the module:

### checksum

```ts
function checksum(
	input: string | Buffer | Uint8Array | Stream.Readable,
	algorithm: string,
	encoding: 'base64' | 'base64url' | 'hex' = 'hex'
): Promise<string>;
```

Accepts `input`, and creates a checksum out of it using requested `algorithm`.

#### `input`

Type: `string | Buffer | Uint8Array | Stream.Readable`

#### `algorithm`

Type: `string`

Can be `crc32` or any algorithm supported by `crypto.createHash(algorithmName)` of the current Node.js process.

#### `encoding`

Type: `'base64' | 'base64url' | 'hex'` _optional_
Default: `hex`

What encoding should the checksum be digested into. Default is `hex`.

#### Returns

Promise that resolves with checksum hash.

### checksumFile

```ts
function checksumFile(
	path: string,
	algorithm: string,
	encoding: 'base64' | 'base64url' | 'hex' = 'hex'
): Promise<string>;
```

Accepts file `path`, and creates a checksum of it using requested `algorithm`.

#### `path`

Type: `string`

Path to a file.

#### `algorithm`

Type: `string`

Can be `crc32` or any algorithm supported by `crypto.createHash(algorithmName)` of the current Node.js process.

#### `encoding`

Type: `'base64' | 'base64url' | 'hex'` _optional_
Default: `hex`

What encoding should the checksum be digested into. Default is `hex`.

#### Returns

Promise that resolves with checksum hash.

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