Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Created August 22, 2018 15:48
Show Gist options
  • Select an option

  • Save stephenplusplus/4e60ffe883ef8cfdbeb3f67bf390c064 to your computer and use it in GitHub Desktop.

Select an option

Save stephenplusplus/4e60ffe883ef8cfdbeb3f67bf390c064 to your computer and use it in GitHub Desktop.
crc32c in action

Yep, it is the same hash as if we had the full value. Here is an example:

If we had all the data upfront:

> crc32c(new Buffer('data1data2data3'))
772160458

If we have to calculate bit-by-bit:

> data1 = new Buffer('data1')
> data2 = new Buffer('data2')
> data3 = new Buffer('data3')
> sum = crc32c(data1) // first data chunk
2984452918
> sum = crc32c(data2, sum) // combine second data chunk with "sum"
4234036460
> sum = crc32c(data3, sum) // combine third data chunk with "sum"
772160458
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment