Git Product home page Git Product logo

node-crc's Introduction

Hi, welcome to my Github pages.

Things Related to My Projects

Rust JavaScript TypeScript Java C PHP Golang Bash

Ubuntu Server Linux Mint Android Windows

Tokio Rocket Axum napi-rs iced Node.js Webpack Express Fastify NestJS + Fastify Bootstrap Vite Vue.js Handlebars Tera Sass Nginx Apache httpd Docker

MySQL SQLite MongoDB Redis

node-crc's People

Contributors

daluf avatar dependabot[bot] avatar magiclen avatar rstiller 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

Watchers

 avatar  avatar  avatar

node-crc's Issues

Error installing ^2.0.0 with yarn

When I try to install any version > 2.0.0 with yarn on macOS, I get following error:

[5/5] ๐Ÿ”จ  Building fresh packages...
error /<project-path>/node_modules/node-crc: Command failed.
Exit code: 1
Command: npm run build
Arguments: 
Directory: /<project-path>/node_modules/node-crc
Output:
> [email protected] build
> cargo-cp-artifact -nc index.node -- cargo build --release --message-format=json-render-diagnostics && tsc

Error: could not find the `cargo` executable.

You can find instructions for installing Rust and Cargo at:

    https://www.rust-lang.org/tools/install


Did not copy "cdylib:node-crc"
npm ERR! code 1
npm ERR! path /<project-path>/node_modules/node-crc
npm ERR! command failed
npm ERR! command sh -c cargo-cp-artifact -nc index.node -- cargo build --release --message-format=json-render-diagnostics && tsc

npm ERR! A complete log of this run can be found in:
npm ERR!     /<user-path>/.npm/_logs/2021-06-30T13_29_53_039Z-debug.log

Find the log-file attached:
2021-06-30T13_29_53_039Z-debug.log

[Q] How to do a CRC8

I have following information:
image

and would like to calculate crc8 but somehow fail to get it working:

const result = crc.crc8(
    0x00, // polyLow
    0x31, // polyHigh
    8,
    0xFF, // initLow
    0xFF, // initHigh
    0x00, // XORlow
    0x00, // XORhigh
    false, // reflect
    Buffer.from([0xBE, 0xEF])
).toString('hex'));

Any pointer to where I'm wrong is appreciated. Thanks in advance.

crc64 can't get right answer

I tried to calculate crc64 use nodejs, but result not right. I don't known how to fix it.

chatimg:73C393EEE6BA2A917FADD8F675985B8C --> 79e215c8f13ee1e7

const str = 'chatimg:73C393EEE6BA2A917FADD8F675985B8C';

let crc64 = crc.crc64(Buffer.from(str, 'utf8')).toString('hex');
console.log('crc64', crc64);
let crc64iso = crc.crc64iso(Buffer.from(str, 'utf8')).toString('hex');
console.log('crc64iso', crc64iso);
let crc64we = crc.crc64we(Buffer.from(str, 'utf8')).toString('hex');
console.log('crc64we', crc64we);
let crc64jones = crc.crc64jones(Buffer.from(str, 'utf8')).toString('hex');

crc64         7d7321185ff00066
crc64iso      0af647013d36de24
crc64we       8d660404ae4f9979
crc64jones    d8f4c927afc207af

I try to crc.crc methods but throw Error

const str = 'chatimg:73C393EEE6BA2A917FADD8F675985B8C';
crc.crc(
        0x95ac9329ac4bc9b5,
        0x00000000,
        64,
        0xffffffffffffffff,
        0x00000000,
        0x00000000,
        0x00000000,
        false,
        Buffer.from(str, 'utf8'),
    )
    .toString('hex');
// RangeError: 9223372036854775807 is bigger than 4294967295

I found python and java script is ok.

//copied from http://www.java2s.com/example/java/security/a-function-that-returns-a-64bit-crc-for-string.html
class CRC64 {
    private static final long[] CRCTable = new long[256];
    private static final long POLY64REV = 0x95AC9329AC4BC9B5L;
    private static final long INITIALCRC = 0xFFFFFFFFFFFFFFFFL;
    private static boolean init = false;

    /**
     * A function that returns a 64-bit crc for string
     *
     * @param in input string
     * @return 64-bit crc value
     */
    public static final long crc64Long(String in) {
        if (in == null || in.length() == 0) {
            return 0;
        }
        long crc = INITIALCRC, part;
        if (!init) {
            for (int i = 0; i < 256; i++) {
                part = i;
                for (int j = 0; j < 8; j++) {
                    int value = ((int) part & 1);
                    if (value != 0) {
                        part = (part >> 1) ^ POLY64REV;
                    } else {
                        part >>= 1;
                    }
                }
                CRCTable[i] = part;
            }
            init = true;
        }
        int length = in.length();
        for (int k = 0; k < length; ++k) {
            char c = in.charAt(k);
            crc = CRCTable[(((int) crc) ^ c) & 0xff] ^ (crc >> 8);
        }
        return crc;
    }
}

        Long c = CRC64.crc64Long("chatimg:73C393EEE6BA2A917FADD8F675985B8C");
        String x = Long.toHexString(c);
        System.out.println(x);
 // 79e215c8f13ee1e7
#!/usr/bin/python
# https://c.runoob.com/compile/9/
_crc64_init = False
_crc64_table = [0] * 256


def crc64(s):
    global _crc64_init
    if not _crc64_init:
        for i in range(256):
            bf = i
            for j in range(8):
                if bf & 1 != 0:
                    bf = bf >> 1 ^ -7661587058870466123
                else:
                    bf >>= 1
            _crc64_table[i] = bf
        _crc64_init = True
    v = -1
    for i in range(len(s)):
        v = _crc64_table[(ord(s[i]) ^ v) & 255] ^ v >> 8
    return v

filename = hex(crc64("chatimg:73C393EEE6BA2A917FADD8F675985B8C"))
print(filename)
# 0x79e215c8f13ee1e7

Dynamically import crc algorithm

I am developing an application that uses this lib, in which I have given the support of multiple CRC algorithms, and when users finally run the config they created, those data is passed to a function, in which data to apply crc and algorithm and it returns calculated crc

import * as crc from 'node-crc';

const crcRunner = (props: { bufferData: Buffer; algoSubType: string }) => {
  const { bufferData, algoSubType } = props;

  const crcAlgo = crc.[algoSubType]

  return '';
};

here when I try to use the CRC algorithm, it throws an error of

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'type of import("c:/Abhishek/Projects/fuota.io-binary-preparation-tool/node_modules/node-crc/lib/lib")'.
No index signature with a parameter of type 'string' was found on type 'type of import("c:/Abhishek/Projects/fuota.io-binary-preparation-tool/node_modules/node-crc/lib/lib")'

Can somebody help me with this problem?

Add changelog?

Please add a changelog. It would help when upgrading major versions (e.g. 1.3.2 -> 2.0.10) to check for problems with deprecations etc. in advance.

Prebuilt binaries to avoid requiring Rust tooling everywhere

Given the change over to using rust, and the lack of rust tooling in most CI infrastructure by default, it might be nice to provide prebuilt binaries.

There are a few solutions to this, https://github.com/prebuild/prebuildify appears to be one of the most modern solutions to this problem, it includes the prebuilt binaries in the package so no extra downloads needed. https://github.com/prebuild/prebuild-install is an older solution but I've seen it used pretty successfully, artifacts are separate and you use github releases to host them. Since you've already moved to github actions, it should make the configuration pretty simple, if the artifacts end up hosted in the github releases. I've not looked into if there are any special considerations for doing this with Neon.

If this is interesting to you, I can spend some time trying to make this work and provide a PR within the next 2-3 weeks.

Installation errors

On my computer it installs fine, but on my Amazon Linux instance it gives an error

137 verbose stack Error: [email protected] install: `node-gyp rebuild`
137 verbose stack Exit status 1
137 verbose stack     at EventEmitter.<anonymous> (/home/ec2-user/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/npm-lifecyc$
137 verbose stack     at EventEmitter.emit (events.js:189:13)
137 verbose stack     at ChildProcess.<anonymous> (/home/ec2-user/.nvm/versions/node/v10.15.3/lib/node_modules/npm/node_modules/npm-lifecyc$
137 verbose stack     at ChildProcess.emit (events.js:189:13)
137 verbose stack     at maybeClose (internal/child_process.js:970:16)
137 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
138 verbose pkgid [email protected]
139 verbose cwd /home/ec2-user/XXXX
140 verbose Linux 4.14.109-80.92.amzn1.x86_64
141 verbose argv "/home/ec2-user/.nvm/versions/node/v10.15.3/bin/node" "/home/ec2-user/.nvm/versions/node/v10.15.3/bin/npm" "install"
142 verbose node v10.15.3
143 verbose npm  v6.4.1
144 error code ELIFECYCLE
145 error errno 1
146 error [email protected] install: `node-gyp rebuild`
146 error Exit status 1
147 error Failed at the [email protected] install script.
147 error This is probably not a problem with npm. There is likely additional logging output above.
148 verbose exit [ 1, true ]

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.