Giter Club home page Giter Club logo

crc's Introduction

crc

Functions for calculating Cyclic Redundancy Checks (CRC) values for the Node.js and front-end.

Features

  • Written in TypeScript and provides typings out of the box.
  • Supports ESM and CommonJS.
  • Pure JavaScript implementation, no native dependencies.
  • Full test suite using pycrc as a refenrence.
  • Supports for the following CRC algorithms:
    • CRC1 (crc1)
    • CRC8 (crc8)
    • CRC8 1-Wire (crc81wire)
    • CRC8 DVB-S2 (crc8dvbs2)
    • CRC16 (crc16)
    • CRC16 CCITT (crc16ccitt)
    • CRC16 Modbus (crc16modbus)
    • CRC16 Kermit (crc16kermit)
    • CRC16 XModem (crc16xmodem)
    • CRC24 (crc24)
    • CRC32 (crc32)
    • CRC32 MPEG-2 (crc32mpeg2)
    • CRCJAM (crcjam)

Installation

npm install crc

Usage

Using specific CRC is the recommended way to reduce bundle size:

import crc32 from 'crc/crc32';
crc32('hello').toString(16);
// "3610a686"

Alternatively you can use main default export:

import crc from 'crc';
crc.crc32('hello').toString(16);
// "3610a686"

If you really wish to minimize bundle size, you can import CRC calculators directly and pass an instance of Int8Array:

import crc32 from 'crc/calculators/crc32';
const helloWorld = new Int8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]);
crc32(helloWorld).toString(16);
// "3610a686"

CommonJS is supported as well without the need to unwrap .default:

const crc32 = require('crc/crc32');
crc32('hello').toString(16);
// "3610a686"

Calculate a CRC32 of a file:

crc32(fs.readFileSync('README.md', 'utf-8')).toString(16);
// "127ad531"

Or using a Buffer:

crc32(fs.readFileSync('README.md', 'utf-8')).toString(16);
// "127ad531"

Incrementally calculate a CRC:

let value = crc32('one');
value = crc32('two', value);
value = crc32('three', value);
value.toString(16);
// "9e1c092"

Tests

npm test

Thanks!

pycrc library is which the source of all of the CRC tables.

License

The MIT License (MIT)

Copyright (c) 2014 Alex Gorbatchev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

crc's People

Contributors

alexgorbatchev avatar alunny avatar azu avatar chris-jamieson avatar gmethvin avatar grabofus avatar huyx avatar ivansanchez avatar junosuarez avatar kaufmo avatar larshp avatar lmommaerts avatar mithgol avatar onip avatar overra avatar phra avatar ssproessig avatar thebadger412 avatar tj avatar underbluewaters avatar zamiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crc's Issues

cross-platform crc32

Hi

It seems crc32 hash is not generating the same hash value on windows and ios.
Is there any way I can get the consistent hash value for the same file on different platforms?
Thanks.

`new Buffer` usage

In this commit. the use of Buffer is replaced with new Buffer, but (despite the misleading text of the deprecation warning), the latter is deprecated as well, and shouldn't be used either, for security reasons. This post explains why.

A polyfill is available to use the new, safer API will still supporting older Node.js versions.

crc32 incorrectly outputs a negative value

For example, crc32("Hello, world") should output: e79aa9c2, but 0-199aa9c2 is output instead. -199aa9c2 might be acceptable, but it really should output the unsigned value e79aa9c2.

Thanks for re-working this lib! Looks great!

About hex ccitt

String "242400111406055059ffff5000"
ASCII
CRC-CCITT (0xFFFF) 0x8BE2,
HEX
CRC-CCITT (0xFFFF) 0xE9B6

HOW can I get the hex CCITT? thank!

root@i-hz06zez9:/usr/local/dcs# node hex
13 bytes: 242400111406055059ffff5000
13 bytes: $$P
8be2

root@i-hz06zez9:/usr/local/dcs# cat hex
var crc = require('crc');

buf = new Buffer(256);
len = buf.write("242400111406055059ffff5000","hex");
console.log(len + " bytes: " + buf.toString('hex',0,len))
var he = buf.toString('hex',0,len);
console.log(len + " bytes: " + buf.toString('ascii',0,len))
console.log(crc.crc16ccitt(he));

Example code in doc does not run

When I try to run a simple example from the doc such as this:

let value = crc32('one');
value = crc32('two', value);
value = crc32('three', value);
value.toString(16);
// "9e1c092"

I get this error:

D:\code\GitHub\file-checker\node_modules\node-crc\lib\lib.js:495
    return _crc.crc32(data);
                ^

TypeError: failed to downcast any to Buffer
    at Object.crc32 (D:\code\GitHub\file-checker\node_modules\node-crc\lib\lib.js:495:17)
    at file:///D:/code/GitHub/file-checker/index.js:17:17
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

And, the source of that error is this line of code in node-crc\lib\lib.js:

const crc32 = (data) => {
    return _crc.crc32(data);
};

Which does not even pass the 2nd argument so even if it got past this error, it does not look like it supports the calling style where you pass in the previous crc value because you're accumulating a crc value across many calls. It appears that the documentation is for some other library and not this particular code.

CRC-32B? Endianness?

Hello!

Thank you for developing and maintaining node-crc.

This is probably a n00b question, but when running against a test file (below), with the code below, I receive a calculated value of 'd5e004dd'. However, when I open the file in iHex it tells me that the CRC32 should be '05ea0cdd' and that the CRC32B is 'dd04e0d5'.

Note that the value returned by node-crc does not match CRC32 but, instead, matches CRC32B with the byte order reversed.

Can someone help me understand these results?

(Note: the test file below is from an effort I'm undertaking to porting to NodeJS Nayuki Minase's approach to forcing CRC-32 values)

Code Sample:

"use strict";
var fs = require('fs'),
    crc = require('crc');
console.log(crc.crc32(fs.readFileSync("testfile.txt", 'utf8')).toString(16));

testfile.txt:

This is a test file. The last four bytes of this file are changed to force a particular CRC value. XXXX

Were the semantics changed from version 2.1.1?

Version 2.1.1 returned a hex string, but version 3.0 returns a number

### 3.0
$ git log | head -n 1
commit c237dc7c5ac10d4fb37ca54a7c57a2cbbb953449
$ node -pe 'require("./").crc32("\u00FF")'
4207949935

### 2.1.1
$ git checkout ce78fddb2b8a51c7081913f78df32906442893a5
$ node -pe 'require("./").crc32("\u00FF")'
fad0386f

Wondering if that was intentional ...

Install error: failed to parse the `edition` key

If you get an install error that has these in it:

failed to parse the edition key

or

supported edition values are 2015or2018, but 2021 is unknown

Then, it's likely because your version of rust is out of date and you need to update it. I was able to update mine by just typing:

rustup update

And, then the installation issue disappeared. It might be useful if the doc for this module explains this dependency.

How to reverse crc.crc16ccitt?

Is there any way to reverse the output of crc.crc16ccitt back to original input string? Is there any undocumented method to do this? Please help

Publish to NPM

The node module on NPM is out of date. It doesn't have the new Buffer support. Please publish.

Release tagging?

Releases after 3.1.0 have not been tagged in git (and consequently do not appear in the "Releases" tab on Github). Since npmjs.com strips test directories out of their tarballs, it is important to have the github tarballs as well for packaging purposes. Could you please tag your releases?

Thanks!

Cannot find module './define_crc'

Hi

I am having the following error after express-session upgraded its dependencies to the latest node-crc version (using node 0.10):

Error: Cannot find module './define_crc'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/lib/openshift/54d0254bfcf9332adf0000a6/app-root/runtime/repo/node_modules/express-session/node_modules/crc/lib/crc1.js:5:19)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
module.js:340
    throw err;
          ^

See :
expressjs/session#267

Wrong crc16-ccitt return value?

Hi, 66236366675F676574400D0A should return crc 5288. Using the following code I get the wrong value:

var crc16 = crc.crc16ccitt(new Buffer('66236366675F676574400D0A','hex')).toString(16); //73E1

Reading the documentation of how to calculate crc from this HEX and get 10F2 It said that It uses the following C code:

unsigned short crc_16_rec(unsigned char * pucData, unsigned short ucLen) {
  //--------------------------------------------------------------------
  unsigned int i;
  unsigned char ucBit, ucCarry;
  //--------------------------------------------------------------------
  unsigned short usPoly = 0x8408; //reversed 0x1021
  unsigned short usCRC = 0;
  //--------------------------------------------------------------------
  for (i = 0; i < ucLen; i++) {
    usCRC ^= pucData[i];
    for (ucBit = 0; ucBit < 8; ucBit++) {
      ucCarry = usCRC & 1;
      usCRC >>= 1;
      if (ucCarry) {
        usCRC ^= usPoly;
      }
    }
  }
  return usCRC;
}

Is the polynimial different? Whats causing this issue?

edit:
Sorry, I've made a slight error, the result shouldn't be 0x10F2 as I've said before It should be 0x5288

Thank you.

CRC-32 incorrect handling of the 0 seed

discussed in #66 but the original analysis was incorrect because it did not actually test the case where 0 is the previous value.

Ruby code:

require 'zlib'

puts("no initial value   : #{(Zlib::crc32('1')).to_s(16)}")     # no initial value   : 83dcefb7
puts("with initial value : #{Zlib::crc32('1', 0).to_s(16)}")    # with initial value : 83dcefb7

Using crc-32:

const CRC32 = require('crc-32');
console.log(`no initial value   : ${(CRC32.bstr('1')>>>0).toString(16)}`);    // no initial value   : 83dcefb7
console.log(`with initial value : ${(CRC32.bstr('1', 0)>>>0).toString(16)}`); // with initial value : 83dcefb7

Using crc:

const {crc32} = require('crc');
console.log(`no initial value   : ${crc32('1').toString(16)}`);     // no initial value   : 83dcefb7
console.log(`with initial value : ${crc32('1', 0).toString(16)}`);  // with initial value : ae21ffc5

The error is in the special 0 case, which probably stems from a misinterpretation of the english description.

The APPNOTE.TXT specification states:

       The proper CRC pre and post
       conditioning is used, meaning that the CRC register
       is pre-conditioned with all ones (a starting value
       of 0xffffffff) and the value is post-conditioned by
       taking the one's complement of the CRC residual.

Some developers misinterpret that to mean the seed starts at -1. but it's actually saying that the crc variable starts at -1:

const crc32: CRCCalculator<Uint8Array> = (current, previous) => {
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  let crc = previous === 0 ? 0 : ~~previous! ^ -1;
  // ^^^^ This `crc` variable is the "CRC register"

  for (let index = 0; index < current.length; index++) {
    crc = TABLE[(crc ^ current[index]) & 0xff] ^ (crc >>> 8);
  }

  return crc ^ -1;
};

There is no need to special-case the 0, and the TS code might as well be simplified to:

const crc32: CRCCalculator<Uint8Array> = (current, previous = 0) => {
  let crc = previous ^ -1; // no need to coerce to 32 bit signed int

  for (let index = 0; index < current.length; index++) {
    crc = TABLE[(crc ^ current[index]) & 0xff] ^ (crc >>> 8);
  }

  return crc ^ -1;
};

ERROR in ./node_modules/crc/cjs-default-unwrap/index.js

Hi Team,

crc version 4.3.0 has an issue with the file not being found. Can you please fix and release a patch version - would be really helpful and will prevent us to pin to 4.1.1 .

Module not found: Error: Can't resolve './crc32mpeg' in '/Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap'
resolve './crc32mpeg' in '/Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap'
  using description file: /Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap/package.json (relative path: .)
    using description file: /Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap/package.json (relative path: ./crc32mpeg)
      no extension
        /Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap/crc32mpeg doesn't exist
      .js
        /Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap/crc32mpeg.js doesn't exist
      .json
        /Users/kkiran/IdeaProjects/cms/node_modules/crc/cjs-default-unwrap/crc32mpeg.json doesn't exist

Thank you.

Conflict with a crc return

Hi,
I was trying check this string: "A000000396564341".
I've calculated this crc with this page. The return crc-16 was 0x0D3F, if we ignore the 0x the result would be 0D3F and I consider the same string with node-crc, but the result is D3F, this library ignore 0. Why does this happend?

Having a parameter of number of bytes to use from source buffer

Hi,

It would be nice to have a parameters of number of bytes to use from source to compute the CRC.
Ex :

var buffer = new Buffer(256);
for (var i = 0; i < 10; ++i) {
buffer[i] = i;
}
var theCRC = crc.crc16modbus(buffer, 10);

This way, we don't have to call buffer.slice to compute a CRC of the first 10 bytes of this buffer and also it allow us to operate only on a subset of the buffer.

Or better, two optional parameters from/to
crc.crc16modbus(buffer, 5, 10);

Best regards,

By the way thank you for your excellent work on this library.

Can't resolve './calculators/crc32'

Error: Module not found: Error: Can't resolve './calculators/crc32' in '.../node_modules/crc'

Getting this error when I try to use [email protected]

My import:

import crc32 from 'crc/crc32';

My tsconfig:

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "lib": [
      "es2018",
      "dom"
    ],
    "module": "es2020",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    // "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "./dist/out-tsc",
    "paths": {
      "@app/*": ["src/app/*"],
      "@env/*": ["src/environments/*"],
      "@testing/*": ["src/testing/*"],
      "firebase-app": ["src/firebase-app.ts"]
    },
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2015"
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

SImilar errors are reported when I try import { crc32 } from 'crc'; (Which is what I did in 3.8.0) and import crc from 'crc';

Some characters are being hashed as the same character

node-crc doesnt seem to work with some characters, for example 1 and ر are hashed as the same character

require('crc32')('1') === '83dcefb7'
require('crc32')('ر') === '83dcefb7'
require('crc32')('Number 1!!!') === '2f705ace'
require('crc32')('Number ر!!!') === '2f705ace'

crc32 gives incorrect checksum when seed is 0

Consider the following:

const {crc32} = require('crc');
> crc32([1], 0);
2298007401
> crc32([1], undefined);
2768625435

A seed value of 0 should be treated the same as no seed value (i.e seed value undefined).

2768625435 is the value that should be returned from the call to crc32([1], 0).

crc return type

My understanding is that a CRC is a hash not a number. Should it return a Buffer instead of a Number type ?

CRC Results between two versions appears to be different

This feels like user error, but the use case is so simple, it appears as a defect.

The following code snippet produces two different results in version 0.2.0 and 3.2.1

var crc = require('crc');

var buff = new Buffer('AR0AAAGP2KJc/vg/AAAAErgGAK8dAAgLAQAAPpo=', 'base64');
var stored_crc = buff.readUInt16LE(27);
var chunked_buff = buff.slice(0,27);
var computed_crc = crc.crc16(chunked_buff);

console.log(buff);
console.log(chunked_buff);
console.log('crc: ' + stored_crc.toString(16));
console.log('computed crc: ' + computed_crc.toString(16));

0.2.0 Results

Note that this version has a slightly different implementation. the crc16 (line 6) has the following syntax,
crc.buffer.crc16(chunked_buff);

node index.js
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00 3e 9a
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00
crc: 9a3e
computed crc: 9a3e

3.2.1 Results

node index.js
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00 3e 9a
Buffer 01 1d 00 00 01 8f d8 a2 5c fe f8 3f 00 00 00 12 b8 06 00 af 1d 00 08 0b 01 00 00
crc: 9a3e
computed crc: f57c

Typescript NodeJS problems

Hello i had problems with use the library using typescript


import { Buffer } from 'buffer';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:881:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
at Module.load (internal/modules/cjs/loader.js:798:32)
at Function.Module._load (internal/modules/cjs/loader.js:711:12)
at Module.require (internal/modules/cjs/loader.js:838:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/dsistemas/Escritorio/Node_JS/19-10-2019/TypeORM-01/src/database/entity/Route.ts:3:1)
at Module._compile (internal/modules/cjs/loader.js:945:30)
at Module.m._compile (/home/dsistemas/Escritorio/Node_JS/19-10-2019/TypeORM-01/node_modules/ts-node/src/index.ts:392:23)
at Module._extensions..js (internal/modules/cjs/loader.js:962:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: ts-node src/index.ts
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/dsistemas/.npm/_logs/2019-10-20T21_33_40_705Z-debug.log

Add support for Reverse Bit Order

I need CCITT-BR. One could add an option on the base CRC that would allow the use of any of the CRC algorithms with reverse bit order.

`buffer` should be optional

yarn v1 and pnpm show buffer warning/error on installing crc.

❯ yarn add crc
yarn add v1.22.19
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > [email protected]" has unmet peer dependency "buffer@>=6.0.3".
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
✨  Done in 0.13s.
pnpm i crc
Packages: +1
+
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /Users/azu/Library/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm

dependencies:
+ crc 4.3.1

 WARN  Issues with peer dependencies found
.
└─┬ crc 4.3.1
  └── ✕ missing peer buffer@>=6.0.3
Peer dependencies that should be installed:
  buffer@>=6.0.3

Progress: resolved 1, reused 1, downloaded 0, added 1, done
Done in 287ms

Also, npm 7+ install peerDependencies by default.

❯ npm i crc

added 4 packages in 85ms

3 packages are looking for funding
  run `npm fund` for details

❯ ls node_modules
total 8
drwxr-xr-x   7 azu  staff   224B  1 29 08:14 .
drwxr-xr-x   6 azu  staff   192B  1 29 08:14 ..
-rw-r--r--   1 azu  staff   2.3K  1 29 08:14 .package-lock.json
drwxr-xr-x   8 azu  staff   256B  1 29 08:14 base64-js
drwxr-xr-x   8 azu  staff   256B  1 29 08:14 buffer
drwxr-xr-x  28 azu  staff   896B  1 29 08:14 crc
drwxr-xr-x   7 azu  staff   224B  1 29 08:14 ieee754

This is because crc has buffer as peerDependencies, but it is not optional.

Solution

Use peerDependenciesMeta to mark buffer as optional.

{
  "peerDependencies": {
    "buffer": ">=6.0.3"
  },
  "peerDependenciesMeta": {
    "buffer": {
      "optional": true
    }
  }
}

I think that buffer is optional because crc can work without external buffer package.
buffer is built-in modules.

import { builtinModules } from 'node:module';
console.log(builtinModules);
/* [
  '_http_agent',         '_http_client',        '_http_common',
  '_http_incoming',      '_http_outgoing',      '_http_server',
  '_stream_duplex',      '_stream_passthrough', '_stream_readable',
  '_stream_transform',   '_stream_wrap',        '_stream_writable',
  '_tls_common',         '_tls_wrap',           'assert',
  'assert/strict',       'async_hooks',         'buffer',
  'child_process',       'cluster',             'console',
  'constants',           'crypto',              'dgram',
  'diagnostics_channel', 'dns',                 'dns/promises',
  'domain',              'events',              'fs',
  'fs/promises',         'http',                'http2',
  'https',               'inspector',           'module',
  'net',                 'os',                  'path',
  'path/posix',          'path/win32',          'perf_hooks',
  'process',             'punycode',            'querystring',
  'readline',            'repl',                'stream',
  'stream/consumers',    'stream/promises',     'stream/web',
  'string_decoder',      'sys',                 'timers',
  'timers/promises',     'tls',                 'trace_events',
  'tty',                 'url',                 'util',
  'util/types',          'v8',                  'vm',
  'worker_threads',      'zlib'
]*/

It is for browser environment.

References

CRC-CCITT (0x1D0F)

Would it be possible to add support for CRC-CCITT 16-bit with the initial value of 0x1D0F and a final XOR value of 0x0000? Thanks

Slowness

So I'm making this here before I forget about it and stuff. I was going to switch express and everything to use this module, but it turns out crc.crc32 is way slower than require('buffer-crc32').unsigned for whatever reason. It may be worth looking into why that is :)

CRC32 for a HEX input

I want to run the CRC32 on a Hex input and produce a Hex output.
But when I do that with this library, it considers the Hex input as a string.

Nomenclature of CRC functions

@alexgorbatchev - I ran a few of the CRC functions and came up with the following (as of the last commit affe249):

  • crc16Arc(...) is "normal" CRC-16 with 0x8005 polynomial. Why is it called crc16Arc? I've personally never heard that before...
  • crc16(...) is not normal CRC-16 with 0x8005 polynomial; it's CRC-CCITT (XModem, 0x1021 polynomial)
  • crc16CCITT(...) is no longer implemented, but it used to be CRC-CCITT (0xFFFF).

Checkout http://www.lammertbies.nl/comm/info/crc-calculation.html for more info.

Latest version does not work on node4 anymore.

/home/raynos/uber/tchannel-node/node_modules/crc/lib/crc32.js:21
  if (!_buffer.Buffer.isBuffer(buf)) buf = (0, _create_buffer2.default)(buf);
                                                                       ^

TypeError: this is not a typed array.
    at from (native)
    at /home/raynos/uber/tchannel-node/node_modules/crc/lib/crc32.js:21:72
    at fn (/home/raynos/uber/tchannel-node/node_modules/crc/lib/define_crc.js:9:12)
    at Object.<anonymous> (/home/raynos/uber/tchannel-node/test/v2/args.js:104:48)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Object.Module._extensions.(anonymous function) [as .js] (/home/raynos/uber/tchannel-node/node_modules/istanbul/lib/hook.js:109:37)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

Node version, v4.4.7

Missing licensing information

Hello,

I'm packaging node-crc for Debian, and it's missing any licensing information. The only information is in the code, and refers to the various original pieces of software you took parts from.

Also, some parts of the code are taken from RFCs. Unfortunately, RFC documents aren't free for use, but are copyrighted by the IETF. Please have a look at RFC2223, section #11.

Thank you,
David

Internet Explorer issue

Hi there,

I'm trying to utilize the crc32 module in my react application. However, as soon as the module is imported the application is not able to load on Internet Explorer. I get the following console error:

WebSocket Error: Network Error 12030, The connection with the server was terminated abnormally

Any ideas what can be done to avoid this?

Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.