How to use crc - 10 common examples

To help you get started, we’ve selected a few crc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexgorbatchev / node-crc / webpack-test / index.js View on Github external
import crc32 from 'crc/crc32';
import crc from 'crc';

// eslint-disable-next-line no-console
console.log(crc32('hello world'), crc.crc32('hello world'));
github pulsar-heavy-industries / phi / www / src / midi.js View on Github external
rd++

                        // see how many bytes we will be processing in this chunk
                        let chunk = Math.min(7, data.length - rd)

                        for (let i = 0; i < chunk; ++i)
                        {
                            data[w] = data[rd] | ( (bits & (1 << i)) ? 0x80 : 0 )
                            rd++
                            w++
                        }
                    }

                    let crc1 = data[0] | (data[1] << 8)
                    data = data.slice(2, w)
                    let crc2 = crc16ccitt(data)

                    if (crc1 === crc2)
                    {
                        this.emitter.emit('in-sysex', data)
                    }
                    else
                    {
                        console.log('SYSEX BAD CRC', crc1, crc2, data)
                    }
                }
                break

            default:
                console.log('Unknown MIDI data', data)
                break
        }
github MahjongPantheon / pantheon / Tyr / src / app / primitives / appstate / index.ts View on Github external
init() {
    let loc = window.location.pathname.replace(/^\//, '');
    if (loc.length > 0) {
      let [pin, crc] = loc.split('_');
      if (crc32(pin).toString(16).toLowerCase() === crc.toLowerCase()) {
        window.history.pushState({}, '', '/'); // to remove pathname
        this.storage.delete(['authToken']);
        this._currentScreen = 'login';
        this.loginWithPin(pin)
          .then(() => {
            this.init(); // Should not enter endless loop because path should be empty here.
          })
          .catch((e) => {
            console.error(e);
            this.metrika.track(MetrikaService.LOAD_ERROR, {
              type: 'state-init-login',
              request: 'confirmRegistration',
              message: e.toString()
            });
          });
        return;
github Cloud-Automation / node-modbus / src / modbus-serial-client.js View on Github external
var onData = function (pdu) {
      this.log.debug('received data')
      if (crc.crc16modbus(pdu) === 0) { /* PDU is valid if CRC across whole PDU equals 0, else ignore and do nothing */
        this.emit('data', pdu.slice(1))
      }
    }.bind(this)
github MahjongPantheon / pantheon / Tyr / src / app / services / qr.ts View on Github external
canvas.drawImage(this._video, 0, 0, canvasElement.width, canvasElement.height);
        let imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
        let code = jsQR(imageData.data, imageData.width, imageData.height, {
          inversionAttempts: 'dontInvert',
        });

        if (code) {
          let pincode = '';
          let data = code.data.match(/^https?:\/\/(.*?)\/(\d+)_([\da-f]+)$/i);
          if (data) {
            if (data[1].split(':')[0] === 'localhost') { // local debug
              pincode = data[2];
            } else {
              if (
                data[1].split(':')[0] === location.host &&
                crc32(data[2]).toString(16).toLowerCase() === data[3].toLowerCase()
              ) {
                pincode = data[2];
              }
            }
          }

          if (pincode.length > 0) {
            this._stopVideo();
            this._video.pause();
            this._onPinReceived(pincode);
            return;
          }
        }
      }

      requestAnimationFrame(tick);
github yvele / poosh / packages / poosh-core / src / helpers / options / hash.js View on Github external
let pairs = [];
  forOwn(object, (value, key) => {
    if (value !== undefined && value !== null) {
      pairs.push([key, value]);
    }
  });

  if (!pairs.length) {
    return EMPTY_HASH;
  }

  // Consistant key/value pair ordering
  pairs = sortBy(pairs, pair => pair[0]);

  // eslint-disable-next-line no-magic-numbers
  return crc32(JSON.stringify(pairs)).toString(16);
}
github conveyal / analysis-ui / lib / utils / browsochrones.js View on Github external
async function ensureScenarioLoadedForInstance ({
  bundleId,
  instance,
  modifications,
  scenarioId,
  workerVersion,
  profileRequest,
  updateStatus
}) {
  // hash the modifications to detect any changes that have taken place
  const scenarioHash = crc32(JSON.stringify(modifications))

  // Maybe one day we'll check if anything relevant (the street network) has changed,
  // that would be a performance win
  if (scenarioHash !== instance.scenarioHash || workerVersion !== instance.workerVersion) {
    debug(`scenario ${scenarioId} has changed, updating browsochrones`)
    updateStatus(APPLYING_SCENARIO)
    const scenarioUniqueId = `${scenarioId}-${scenarioHash}`
    const request = getStaticSiteRequest({ modifications, bundleId, scenarioUniqueId, workerVersion, profileRequest })
    // TODO don't duplicate these fields
    const { jobId } = request
    const body = {
      request,
      graphId: bundleId,
      workerVersion,
      jobId
    }
github theVolary / feather / node_modules / connect / lib / utils.js View on Github external
Object.keys(obj).forEach(function(key){
    var val = obj[key];
    if (0 == val.indexOf('j:')) {
      try {
        hashes[key] = crc16(val); // only crc json cookies for now
        obj[key] = JSON.parse(val.slice(2));
      } catch (err) {
        // nothing
      }
    }
  });
github vshymanskyy / blynk-library-js / experiments / ble-to-tcp.js View on Github external
BleBeanSerial.prototype.sendCmd = function(cmdBuffer,payloadBuffer,done) {
  var sizeBuffer = new Buffer(2);
  sizeBuffer.writeUInt8(cmdBuffer.length + payloadBuffer.length,0);
  sizeBuffer.writeUInt8(0,1);

  //GST contains sizeBuffer, cmdBuffer, and payloadBuffer
  var gst = Buffer.concat([sizeBuffer,cmdBuffer,payloadBuffer]);

  var crcString = crc.crc16ccitt(gst);
  var crc16Buffer = new Buffer(2);
  crc16Buffer.writeUInt16LE(crcString, 0);
  
  gst = Buffer.concat([sizeBuffer,cmdBuffer,payloadBuffer,crc16Buffer]);
  
  var gt_qty = Math.floor(gst.length/19);
  if (gst.length % 19 != 0) {
    gt_qty += 1;
  }
  var optimal_packet_size = 19;
  
  for (var ch=0; ch
github jgraph / drawio / src / main / webapp / electron.js View on Github external
{
						outBuff.writeInt8(0, outOffset);
						outOffset ++;
						data.copy(outBuff, outOffset);
					}
					else
					{
						outBuff.write(data, outOffset);	
					}

					outOffset += data.length;				
				}

				var crcVal = 0xffffffff;
				crcVal = crc.crcjam(typeSignature, crcVal);
				crcVal = crc.crcjam(data, crcVal);

				// CRC
				outBuff.writeInt32BE(crcVal ^ 0xffffffff, outOffset);
				outOffset += 4;

				// Writes the IDAT chunk after the zTXt
				outBuff.writeInt32BE(length, outOffset);
				outOffset += 4;
				outBuff.writeInt32BE(type, outOffset);
				outOffset += 4;

				origBuff.copy(outBuff, outOffset, inOffset);

				// Encodes the buffer using base64 if requested
				return base64encoded? outBuff.toString('base64') : outBuff;
			}

crc

Module for calculating Cyclic Redundancy Check (CRC) for Node.js and the browser.

MIT
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis