# cyclic-32

> Tiny, streaming, seedable CRC32 library, compatible with the crypto.Hash API

Latest version **1.2.0** (published 2021-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install cyclic-32
pnpm add cyclic-32
yarn add cyclic-32
bun add cyclic-32
```

Provides the command `crc32`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-09-19 |
| First published | 2017-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonas Hermsmeier |
| Maintainers | jhermsmeier |
| Keywords | crc, crc32, cyclic, 32, checksum, redundancy, stream, crc32-stream, check, seed |

## Links

- npm: https://www.npmjs.com/package/cyclic-32
- Repository: https://github.com/jhermsmeier/node-cyclic-32
- Issues: https://github.com/jhermsmeier/node-cyclic-32/issues
- npm.io page: https://npm.io/package/cyclic-32

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-09-19
- 1.1.1 — 2021-09-19
- 1.1.0 — 2018-12-15
- 1.0.2 — 2018-11-28
- 1.0.1 — 2017-04-18
- 1.0.0 — 2017-04-18

## README

# cyclic-32
[![npm](https://img.shields.io/npm/v/cyclic-32.svg?style=flat-square)](https://npmjs.com/package/cyclic-32)
[![npm license](https://img.shields.io/npm/l/cyclic-32.svg?style=flat-square)](https://npmjs.com/package/cyclic-32)
[![npm downloads](https://img.shields.io/npm/dm/cyclic-32.svg?style=flat-square)](https://npmjs.com/package/cyclic-32)

A tiny, streaming, seedable [CRC32] library, compatible with Node's [crypto.Hash API].
In less than 100 LOC.

[CRC32]: https://en.wikipedia.org/wiki/Cyclic_redundancy_check
[crypto.Hash API]: https://nodejs.org/api/crypto.html#crypto_class_hash

## Install via [npm](https://npmjs.com)

```sh
$ npm install --save cyclic-32
```

## Features

- **Speed:** ~300 MB/s on a 2012 Macbook Air
- **Size:** It's 96 lines of code (plus 22 lines of comments, and 17 blank)
- **Streams:** .pipe().pipe().pipe()
- **Seedable:** If you have more complex things in mind
- **CLI:** Possibly useful for npm run scripts

## Usage

### API

```js
var checksum = crc32( buffer, seed = 0, table = crc32.TABLE.DEFAULT )
```

```js
// Shorthand for Castagnoli
var castagnoli = crc32.c( buffer, seed = 0, table = crc32.TABLE.DEFAULT )
```

```js
var checksumStream = crc32.createHash({
  seed: 0,
  table: crc32.TABLE.DEFAULT,
})
```

**Builtin tables:**

- `crc32.TABLE.DEFAULT`: Standard CRC32
- `crc32.TABLE.CASTAGNOLI`: Castagnoli

### Examples

```js
var crc32 = require( 'cyclic-32' )
```

Calculate the CRC32 checksum of a Buffer:

```js
var buffer = new Buffer( 'I shall be summed', 'ascii' )
console.log( crc32( buffer ) ) // -476443423
```

Pass a seed value:

```js
var buffer = new Buffer( 'I shall be summoned', 'ascii' )
console.log( crc32( buffer, 666 ) ) // -823676065
```

Calculate the CRC32 checksum over a Stream:

```js
fs.createReadStream( filename )
  .pipe( crc32.createHash() )
  .on( 'data', function( buffer ) {
    console.log( 'CRC32:', buffer.toString( 'hex' ) )
  })
```

If you want to pass an `encoding`, or `seed`:

```js
fs.createReadStream( filename )
  .pipe( new crc32.Hash({ encoding: 'hex', seed: -12345678 }) )
  .on( 'data', function( checksum ) {
    console.log( 'CRC32:', checksum )
  })
```

Or, if you'd rather stick to the `crypto.Hash` API:

```js
var hash = crc32.createHash()

hash.update( 'I shall' )
  .update( 'be summed' )

console.log( 'CRC32:', hash.digest( 'hex' ) )
```

## CLI Usage

Calculate the checksum of a file:

```sh
$ crc32 filename
0a0ca5aa
```

Pipe stuff into it via stdin:

```sh
$ cat filename | crc32
ffe6bbc0
```

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