alexgorbatchev / crc

Blazingly fast CRC implementations for node.js and browser
MIT License
349 stars 72 forks source link

Example code in doc does not run #75

Closed jfriend00 closed 1 year ago

jfriend00 commented 1 year ago

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.

alexgorbatchev commented 1 year ago

You maybe looking at an older lib version and newer docs. There's no lib folder in 4.x https://www.npmjs.com/package/crc?activeTab=explore

image