Skip to content

Commit

Permalink
fix: int32 for crc table
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaz committed Mar 27, 2023
1 parent 7861a57 commit f6f0440
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-yenc",
"version": "1.0.0",
"version": "1.0.1",
"description": "Minimalist yEnc and dynEncode encoder and decoder library for browser and NodeJS",
"main": "./dist/index.js",
"module": "./dist/esm.js",
Expand Down
15 changes: 9 additions & 6 deletions src/simple-yenc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/* See https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=libiberty/crc32.c;hb=refs/heads/master */
const crc32 = (buf, init = 0xffffffff, poly = 0x04c11db7) => {
const crc32Table = new Uint8Array(256);
let i, j, c;
const crc32Table = new Int32Array(256);
let i,
j,
c,
crc = init;

for (i = 0; i < 256; i++) {
for (c = i << 24, j = 8; j > 0; --j)
c = c & 0x80000000 ? (c << 1) ^ poly : c << 1;
crc32Table[i] = c;
}

return buf.reduce(
(crc, val) => (crc << 8) ^ crc32Table[((crc >> 24) ^ val) & 255],
init
);
for (i = 0; i < buf.length; i++)
crc = (crc << 8) ^ crc32Table[((crc >> 24) ^ buf[i]) & 255];

return crc;
};

const encode = (byteArray) => {
Expand Down

0 comments on commit f6f0440

Please sign in to comment.