New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tsxper/crc32

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsxper/crc32

Calculates unsigned CRC32.

  • 2.0.0
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

CRC32

Cycle Redundancy Check 32 (CRC32).

Calculates unsigned 32 bit checksum for 0xEDB88320 polynomial.

Compatibility

class CRC32
// Browser and NodeJS compatible.
class CRC32Streams
// Depends on NodeJS "stream" module.

TypeScript Support

"@tsxper/crc32" package is originally written in TypeScript. TypeScript type definitions are included.

Transitive Dependencies

None.

Example

For String

const crc32 = new CRC32();
crc32.calculate('crc32 test');
// or
crc32.forString('crc32 test');

For Uint8Array

const crc32 = new CRC32();
crc32.forBytes(new TextEncoder().encode('crc32 test'));

For Buffer

Buffer extends Uint8Array.

const crc32 = new CRC32();
crc32.forBuffer(new TextEncoder().encode('crc32 test'));

For File

const crc32 = new CRC32Streams();
const checksum = await crc32.forFile(filePath);

In Browser

See "Compatibility".

HTML Copy/Paste Example

<!DOCTYPE html>
<html>
<body>
  <p>Calculating crc32 for text "hello crc32": <span id="placeholder"></span></p>
  <script type="importmap">
    {
      "imports": {
        "@tsxper/crc32": "https://www.unpkg.com/@tsxper/crc32@1.0.5/esm/CRC32.js"
      }
    }
  </script>
  <script type="module">
    import { CRC32 } from "@tsxper/crc32";
    const crc32 = new CRC32();
    const crc = crc32.calculate("hello crc32");
    document.getElementById('placeholder').innerText = crc;
  </script>
</body>
</html>

Customization. Calculate for chunks, chunk by chunk.

For example, for sequence of events, converted into Uint8Array[] chunks.

const chunks = [new TextEncoder().encode('text1 text2')];
const crc32 = new CRC32();
let crc = 0;
for (const chunk of chunks) {
  crc = crc32.forBytes(chunk, crc);
}

Supporting CommonJS and ECMAScript modules

Both, CommonJS and ESM modules are supported.

import { CRC32 } from '@tsxper/crc32';
// or
const { CRC32 } = require('@tsxper/crc32');

Supporting of the both module systems is done through "import", "require" and "default" conditions.

  • Implementing CRC32 in TypeScript.

  • Conditional exports, NodeJS.

  • Package exports, Webpack.

Keywords

FAQs

Package last updated on 04 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc