precompiled-digest-crc 0.7.0-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/cibuildgem.yaml +89 -0
  3. data/.github/workflows/integration.yml +26 -0
  4. data/.github/workflows/ruby.yml +33 -0
  5. data/.gitignore +11 -0
  6. data/.rspec +1 -0
  7. data/.yardopts +1 -0
  8. data/ChangeLog.md +212 -0
  9. data/Gemfile +16 -0
  10. data/LICENSE.txt +20 -0
  11. data/README.md +401 -0
  12. data/Rakefile +57 -0
  13. data/benchmarks.rb +59 -0
  14. data/digest-crc.gemspec +65 -0
  15. data/ext/digest/Rakefile +46 -0
  16. data/ext/digest/compat/ruby.h +11 -0
  17. data/ext/digest/crc12_3gpp/3.3/crc12_3gpp_ext.bundle +0 -0
  18. data/ext/digest/crc12_3gpp/3.4/crc12_3gpp_ext.bundle +0 -0
  19. data/ext/digest/crc12_3gpp/4.0/crc12_3gpp_ext.bundle +0 -0
  20. data/ext/digest/crc12_3gpp/crc12_3gpp.c +68 -0
  21. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  22. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +32 -0
  23. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  24. data/ext/digest/crc15/3.3/crc15_ext.bundle +0 -0
  25. data/ext/digest/crc15/3.4/crc15_ext.bundle +0 -0
  26. data/ext/digest/crc15/4.0/crc15_ext.bundle +0 -0
  27. data/ext/digest/crc15/crc15.c +54 -0
  28. data/ext/digest/crc15/crc15.h +11 -0
  29. data/ext/digest/crc15/crc15_ext.c +33 -0
  30. data/ext/digest/crc15/extconf.rb +7 -0
  31. data/ext/digest/crc16/3.3/crc16_ext.bundle +0 -0
  32. data/ext/digest/crc16/3.4/crc16_ext.bundle +0 -0
  33. data/ext/digest/crc16/4.0/crc16_ext.bundle +0 -0
  34. data/ext/digest/crc16/crc16.c +70 -0
  35. data/ext/digest/crc16/crc16.h +11 -0
  36. data/ext/digest/crc16/crc16_ext.c +33 -0
  37. data/ext/digest/crc16/extconf.rb +7 -0
  38. data/ext/digest/crc16_ccitt/3.3/crc16_ccitt_ext.bundle +0 -0
  39. data/ext/digest/crc16_ccitt/3.4/crc16_ccitt_ext.bundle +0 -0
  40. data/ext/digest/crc16_ccitt/4.0/crc16_ccitt_ext.bundle +0 -0
  41. data/ext/digest/crc16_ccitt/crc16_ccitt.c +70 -0
  42. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  43. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +33 -0
  44. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  45. data/ext/digest/crc16_dnp/3.3/crc16_dnp_ext.bundle +0 -0
  46. data/ext/digest/crc16_dnp/3.4/crc16_dnp_ext.bundle +0 -0
  47. data/ext/digest/crc16_dnp/4.0/crc16_dnp_ext.bundle +0 -0
  48. data/ext/digest/crc16_dnp/crc16_dnp.c +54 -0
  49. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  50. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +33 -0
  51. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  52. data/ext/digest/crc16_genibus/3.3/crc16_genibus_ext.bundle +0 -0
  53. data/ext/digest/crc16_genibus/3.4/crc16_genibus_ext.bundle +0 -0
  54. data/ext/digest/crc16_genibus/4.0/crc16_genibus_ext.bundle +0 -0
  55. data/ext/digest/crc16_genibus/crc16_genibus.c +70 -0
  56. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  57. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +33 -0
  58. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  59. data/ext/digest/crc16_kermit/3.3/crc16_kermit_ext.bundle +0 -0
  60. data/ext/digest/crc16_kermit/3.4/crc16_kermit_ext.bundle +0 -0
  61. data/ext/digest/crc16_kermit/4.0/crc16_kermit_ext.bundle +0 -0
  62. data/ext/digest/crc16_kermit/crc16_kermit.c +70 -0
  63. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  64. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +33 -0
  65. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  66. data/ext/digest/crc16_modbus/3.3/crc16_modbus_ext.bundle +0 -0
  67. data/ext/digest/crc16_modbus/3.4/crc16_modbus_ext.bundle +0 -0
  68. data/ext/digest/crc16_modbus/4.0/crc16_modbus_ext.bundle +0 -0
  69. data/ext/digest/crc16_modbus/crc16_modbus.c +70 -0
  70. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  71. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +32 -0
  72. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  73. data/ext/digest/crc16_usb/3.3/crc16_usb_ext.bundle +0 -0
  74. data/ext/digest/crc16_usb/3.4/crc16_usb_ext.bundle +0 -0
  75. data/ext/digest/crc16_usb/4.0/crc16_usb_ext.bundle +0 -0
  76. data/ext/digest/crc16_usb/crc16_usb.c +70 -0
  77. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  78. data/ext/digest/crc16_usb/crc16_usb_ext.c +32 -0
  79. data/ext/digest/crc16_usb/extconf.rb +7 -0
  80. data/ext/digest/crc16_x_25/3.3/crc16_x_25_ext.bundle +0 -0
  81. data/ext/digest/crc16_x_25/3.4/crc16_x_25_ext.bundle +0 -0
  82. data/ext/digest/crc16_x_25/4.0/crc16_x_25_ext.bundle +0 -0
  83. data/ext/digest/crc16_x_25/crc16_x_25.c +70 -0
  84. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  85. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +32 -0
  86. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  87. data/ext/digest/crc16_xmodem/3.3/crc16_xmodem_ext.bundle +0 -0
  88. data/ext/digest/crc16_xmodem/3.4/crc16_xmodem_ext.bundle +0 -0
  89. data/ext/digest/crc16_xmodem/4.0/crc16_xmodem_ext.bundle +0 -0
  90. data/ext/digest/crc16_xmodem/crc16_xmodem.c +70 -0
  91. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  92. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +33 -0
  93. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  94. data/ext/digest/crc16_zmodem/3.3/crc16_zmodem_ext.bundle +0 -0
  95. data/ext/digest/crc16_zmodem/3.4/crc16_zmodem_ext.bundle +0 -0
  96. data/ext/digest/crc16_zmodem/4.0/crc16_zmodem_ext.bundle +0 -0
  97. data/ext/digest/crc16_zmodem/crc16_zmodem.c +70 -0
  98. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  99. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +33 -0
  100. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  101. data/ext/digest/crc24/3.3/crc24_ext.bundle +0 -0
  102. data/ext/digest/crc24/3.4/crc24_ext.bundle +0 -0
  103. data/ext/digest/crc24/4.0/crc24_ext.bundle +0 -0
  104. data/ext/digest/crc24/crc24.c +70 -0
  105. data/ext/digest/crc24/crc24.h +11 -0
  106. data/ext/digest/crc24/crc24_ext.c +32 -0
  107. data/ext/digest/crc24/extconf.rb +7 -0
  108. data/ext/digest/crc32/3.3/crc32_ext.bundle +0 -0
  109. data/ext/digest/crc32/3.4/crc32_ext.bundle +0 -0
  110. data/ext/digest/crc32/4.0/crc32_ext.bundle +0 -0
  111. data/ext/digest/crc32/crc32.c +69 -0
  112. data/ext/digest/crc32/crc32.h +11 -0
  113. data/ext/digest/crc32/crc32_ext.c +32 -0
  114. data/ext/digest/crc32/extconf.rb +7 -0
  115. data/ext/digest/crc32_bzip2/3.3/crc32_bzip2_ext.bundle +0 -0
  116. data/ext/digest/crc32_bzip2/3.4/crc32_bzip2_ext.bundle +0 -0
  117. data/ext/digest/crc32_bzip2/4.0/crc32_bzip2_ext.bundle +0 -0
  118. data/ext/digest/crc32_bzip2/crc32_bzip2.c +70 -0
  119. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  120. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +32 -0
  121. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  122. data/ext/digest/crc32_jam/3.3/crc32_jam_ext.bundle +0 -0
  123. data/ext/digest/crc32_jam/3.4/crc32_jam_ext.bundle +0 -0
  124. data/ext/digest/crc32_jam/4.0/crc32_jam_ext.bundle +0 -0
  125. data/ext/digest/crc32_jam/crc32_jam.c +70 -0
  126. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  127. data/ext/digest/crc32_jam/crc32_jam_ext.c +31 -0
  128. data/ext/digest/crc32_jam/extconf.rb +7 -0
  129. data/ext/digest/crc32_mpeg/3.3/crc32_mpeg_ext.bundle +0 -0
  130. data/ext/digest/crc32_mpeg/3.4/crc32_mpeg_ext.bundle +0 -0
  131. data/ext/digest/crc32_mpeg/4.0/crc32_mpeg_ext.bundle +0 -0
  132. data/ext/digest/crc32_mpeg/crc32_mpeg.c +70 -0
  133. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  134. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +32 -0
  135. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  136. data/ext/digest/crc32_posix/3.3/crc32_posix_ext.bundle +0 -0
  137. data/ext/digest/crc32_posix/3.4/crc32_posix_ext.bundle +0 -0
  138. data/ext/digest/crc32_posix/4.0/crc32_posix_ext.bundle +0 -0
  139. data/ext/digest/crc32_posix/crc32_posix.c +70 -0
  140. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  141. data/ext/digest/crc32_posix/crc32_posix_ext.c +32 -0
  142. data/ext/digest/crc32_posix/extconf.rb +7 -0
  143. data/ext/digest/crc32_xfer/3.3/crc32_xfer_ext.bundle +0 -0
  144. data/ext/digest/crc32_xfer/3.4/crc32_xfer_ext.bundle +0 -0
  145. data/ext/digest/crc32_xfer/4.0/crc32_xfer_ext.bundle +0 -0
  146. data/ext/digest/crc32_xfer/crc32_xfer.c +70 -0
  147. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  148. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +32 -0
  149. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  150. data/ext/digest/crc32c/3.3/crc32c_ext.bundle +0 -0
  151. data/ext/digest/crc32c/3.4/crc32c_ext.bundle +0 -0
  152. data/ext/digest/crc32c/4.0/crc32c_ext.bundle +0 -0
  153. data/ext/digest/crc32c/crc32c.c +70 -0
  154. data/ext/digest/crc32c/crc32c.h +8 -0
  155. data/ext/digest/crc32c/crc32c_ext.c +31 -0
  156. data/ext/digest/crc32c/extconf.rb +7 -0
  157. data/ext/digest/crc5/3.3/crc5_ext.bundle +0 -0
  158. data/ext/digest/crc5/3.4/crc5_ext.bundle +0 -0
  159. data/ext/digest/crc5/4.0/crc5_ext.bundle +0 -0
  160. data/ext/digest/crc5/crc5.c +54 -0
  161. data/ext/digest/crc5/crc5.h +11 -0
  162. data/ext/digest/crc5/crc5_ext.c +32 -0
  163. data/ext/digest/crc5/extconf.rb +7 -0
  164. data/ext/digest/crc64/3.3/crc64_ext.bundle +0 -0
  165. data/ext/digest/crc64/3.4/crc64_ext.bundle +0 -0
  166. data/ext/digest/crc64/4.0/crc64_ext.bundle +0 -0
  167. data/ext/digest/crc64/crc64.c +102 -0
  168. data/ext/digest/crc64/crc64.h +11 -0
  169. data/ext/digest/crc64/crc64_ext.c +32 -0
  170. data/ext/digest/crc64/extconf.rb +7 -0
  171. data/ext/digest/crc64_jones/3.3/crc64_jones_ext.bundle +0 -0
  172. data/ext/digest/crc64_jones/3.4/crc64_jones_ext.bundle +0 -0
  173. data/ext/digest/crc64_jones/4.0/crc64_jones_ext.bundle +0 -0
  174. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  175. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  176. data/ext/digest/crc64_jones/crc64_jones_ext.c +31 -0
  177. data/ext/digest/crc64_jones/extconf.rb +7 -0
  178. data/ext/digest/crc64_nvme/3.3/crc64_nvme_ext.bundle +0 -0
  179. data/ext/digest/crc64_nvme/3.4/crc64_nvme_ext.bundle +0 -0
  180. data/ext/digest/crc64_nvme/4.0/crc64_nvme_ext.bundle +0 -0
  181. data/ext/digest/crc64_nvme/crc64_nvme.c +102 -0
  182. data/ext/digest/crc64_nvme/crc64_nvme.h +8 -0
  183. data/ext/digest/crc64_nvme/crc64_nvme_ext.c +31 -0
  184. data/ext/digest/crc64_nvme/extconf.rb +7 -0
  185. data/ext/digest/crc64_xz/3.3/crc64_xz_ext.bundle +0 -0
  186. data/ext/digest/crc64_xz/3.4/crc64_xz_ext.bundle +0 -0
  187. data/ext/digest/crc64_xz/4.0/crc64_xz_ext.bundle +0 -0
  188. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  189. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  190. data/ext/digest/crc64_xz/crc64_xz_ext.c +31 -0
  191. data/ext/digest/crc64_xz/extconf.rb +7 -0
  192. data/ext/digest/crc8/3.3/crc8_ext.bundle +0 -0
  193. data/ext/digest/crc8/3.4/crc8_ext.bundle +0 -0
  194. data/ext/digest/crc8/4.0/crc8_ext.bundle +0 -0
  195. data/ext/digest/crc8/crc8.c +54 -0
  196. data/ext/digest/crc8/crc8.h +11 -0
  197. data/ext/digest/crc8/crc8_ext.c +32 -0
  198. data/ext/digest/crc8/extconf.rb +7 -0
  199. data/ext/digest/crc8_1wire/3.3/crc8_1wire_ext.bundle +0 -0
  200. data/ext/digest/crc8_1wire/3.4/crc8_1wire_ext.bundle +0 -0
  201. data/ext/digest/crc8_1wire/4.0/crc8_1wire_ext.bundle +0 -0
  202. data/ext/digest/crc8_1wire/crc8_1wire.c +54 -0
  203. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  204. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +31 -0
  205. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  206. data/gemspec.yml +25 -0
  207. data/lib/digest/crc.rb +211 -0
  208. data/lib/digest/crc1.rb +37 -0
  209. data/lib/digest/crc15.rb +45 -0
  210. data/lib/digest/crc16.rb +61 -0
  211. data/lib/digest/crc16_ccitt.rb +59 -0
  212. data/lib/digest/crc16_dnp.rb +62 -0
  213. data/lib/digest/crc16_genibus.rb +65 -0
  214. data/lib/digest/crc16_kermit.rb +59 -0
  215. data/lib/digest/crc16_modbus.rb +57 -0
  216. data/lib/digest/crc16_qt.rb +11 -0
  217. data/lib/digest/crc16_usb.rb +23 -0
  218. data/lib/digest/crc16_x_25.rb +63 -0
  219. data/lib/digest/crc16_xmodem.rb +57 -0
  220. data/lib/digest/crc16_zmodem.rb +57 -0
  221. data/lib/digest/crc24.rb +61 -0
  222. data/lib/digest/crc32.rb +95 -0
  223. data/lib/digest/crc32_bzip2.rb +57 -0
  224. data/lib/digest/crc32_jam.rb +16 -0
  225. data/lib/digest/crc32_mpeg.rb +94 -0
  226. data/lib/digest/crc32_posix.rb +58 -0
  227. data/lib/digest/crc32_xfer.rb +61 -0
  228. data/lib/digest/crc32c.rb +87 -0
  229. data/lib/digest/crc5.rb +58 -0
  230. data/lib/digest/crc64.rb +95 -0
  231. data/lib/digest/crc64_jones.rb +93 -0
  232. data/lib/digest/crc64_nvme.rb +95 -0
  233. data/lib/digest/crc64_xz.rb +95 -0
  234. data/lib/digest/crc8.rb +45 -0
  235. data/lib/digest/crc8_1wire.rb +42 -0
  236. metadata +322 -0
data/README.md ADDED
@@ -0,0 +1,401 @@
1
+ # Digest CRC
2
+
3
+ [![CI](https://github.com/postmodern/digest-crc/actions/workflows/ruby.yml/badge.svg)](https://github.com/postmodern/digest-crc/actions/workflows/ruby.yml)
4
+
5
+ * [Source](https://github.com/postmodern/digest-crc)
6
+ * [Issues](https://github.com/postmodern/digest-crc/issues)
7
+ * [Documentation](http://rubydoc.info/gems/digest-crc/frames)
8
+
9
+ ## Description
10
+
11
+ Adds support for calculating Cyclic Redundancy Check (CRC) to the Digest
12
+ module.
13
+
14
+ ## Features
15
+
16
+ * Provides support for the following CRC algorithms:
17
+ * [CRC1](https://rubydoc.info/gems/digest-crc/Digest/CRC1)
18
+ * [CRC5](https://rubydoc.info/gems/digest-crc/Digest/CRC5)
19
+ * [CRC8](https://rubydoc.info/gems/digest-crc/Digest/CRC8)
20
+ * [CRC8 1-Wire](https://rubydoc.info/gems/digest-crc/Digest/CRC8_1Wire)
21
+ * [CRC15](https://rubydoc.info/gems/digest-crc/Digest/CRC15)
22
+ * [CRC16](https://rubydoc.info/gems/digest-crc/Digest/CRC16)
23
+ * [CRC16 CCITT](https://rubydoc.info/gems/digest-crc/Digest/CRC16CCITT)
24
+ * [CRC16 DNP](https://rubydoc.info/gems/digest-crc/Digest/CRC16DNP)
25
+ * [CRC16 Genibus](https://rubydoc.info/gems/digest-crc/Digest/CRC16Genibus)
26
+ * [CRC16 Kermit](https://rubydoc.info/gems/digest-crc/Digest/CRC16Kermit)
27
+ * [CRC16 Modbus](https://rubydoc.info/gems/digest-crc/Digest/CRC16Modbus)
28
+ * [CRC16 USB](https://rubydoc.info/gems/digest-crc/Digest/CRC16USB)
29
+ * [CRC16 X25](https://rubydoc.info/gems/digest-crc/Digest/CRC16X25)
30
+ * [CRC16 XModem](https://rubydoc.info/gems/digest-crc/Digest/CRC16XModem)
31
+ * [CRC16 ZModem](https://rubydoc.info/gems/digest-crc/Digest/CRC16ZModem)
32
+ * [CRC16 QT](https://rubydoc.info/gems/digest-crc/Digest/CRC16QT)
33
+ * [CRC24](https://rubydoc.info/gems/digest-crc/Digest/CRC24)
34
+ * [CRC32](https://rubydoc.info/gems/digest-crc/Digest/CRC32)
35
+ * [CRC32 BZip2](https://rubydoc.info/gems/digest-crc/Digest/CRC32BZip2)
36
+ * [CRC32c](https://rubydoc.info/gems/digest-crc/Digest/CRC32c)
37
+ * [CRC32 Jam](https://rubydoc.info/gems/digest-crc/Digest/CRC32Jam)
38
+ * [CRC32 MPEG](https://rubydoc.info/gems/digest-crc/Digest/CRC32MPEG)
39
+ * [CRC32 POSIX](https://rubydoc.info/gems/digest-crc/Digest/CRC32POSIX)
40
+ * [CRC32 XFER](https://rubydoc.info/gems/digest-crc/Digest/CRC32XFER)
41
+ * [CRC64](https://rubydoc.info/gems/digest-crc/Digest/CRC64)
42
+ * [CRC64 Jones](https://rubydoc.info/gems/digest-crc/Digest/CRC64Jones)
43
+ * [CRC64 NVMe](https://rubydoc.info/gems/digest-crc/Digest/CRC64Nvme)
44
+ * [CRC64 XZ](https://rubydoc.info/gems/digest-crc/Digest/CRC64XZ)
45
+ * Pure Ruby implementation.
46
+ * Provides CRC Tables for optimized calculations.
47
+ * Supports _optional_ C extensions which increases performance by ~40x.
48
+ * If the C extensions cannot be compiled for whatever reason, digest-crc
49
+ will automatically fallback to the pure-Ruby implementation.
50
+
51
+ ## Install
52
+
53
+ ```
54
+ gem install digest-crc
55
+ ```
56
+
57
+ **Note:** to enable the C extensions ensure that you are using CRuby and have
58
+ a C compiler (`gcc` or `clang`) and `make` installed, _before_ installing
59
+ digest-crc.
60
+
61
+ * Debian / Ubuntu:
62
+
63
+ $ sudo apt install gcc make
64
+
65
+ * RedHat / Fedora:
66
+
67
+ $ sudo dnf install gcc make
68
+
69
+ * Alpine Linux:
70
+
71
+ $ apk add build-base
72
+
73
+ * macOS: install XCode
74
+
75
+ ## Examples
76
+
77
+ Calculate a CRC32:
78
+
79
+ ```ruby
80
+ require 'digest/crc32'
81
+
82
+ Digest::CRC32.hexdigest('hello')
83
+ # => "3610a686"
84
+ ```
85
+
86
+ Calculate a CRC32 of a file:
87
+
88
+ ```ruby
89
+ Digest::CRC32.file('README.md')
90
+ # => #<Digest::CRC32: 127ad531>
91
+ ```
92
+
93
+ Incrementally calculate a CRC32:
94
+
95
+ ```ruby
96
+ crc = Digest::CRC32.new
97
+ crc << 'one'
98
+ crc << 'two'
99
+ crc << 'three'
100
+ crc.hexdigest
101
+ # => "09e1c092"
102
+ ```
103
+
104
+ Directly access the checksum:
105
+
106
+ ```ruby
107
+ crc.checksum
108
+ # => 165789842
109
+ ```
110
+
111
+ Defining your own CRC class:
112
+
113
+ ```ruby
114
+ require 'digest/crc32'
115
+
116
+ module Digest
117
+ class CRC3000 < CRC32
118
+
119
+ WIDTH = 32
120
+
121
+ REFLECT_INPUT = true
122
+
123
+ INIT_CRC = 0xffffffff
124
+
125
+ XOR_MASK = 0xffffffff
126
+
127
+ TABLE = [
128
+ # ....
129
+ ].freeze
130
+ end
131
+ end
132
+ ```
133
+
134
+ ## Benchmarks
135
+
136
+ ### Ruby 2.7.4 (pure Ruby)
137
+
138
+ $ bundle exec rake clean
139
+ $ bundle exec ./benchmarks.rb
140
+ Loading Digest::CRC classes ...
141
+ Generating 1000 8Kb lengthed strings ...
142
+ Benchmarking Digest::CRC classes ...
143
+ user system total real
144
+ Digest::CRC1#update 0.423741 0.000000 0.423741 ( 0.425887)
145
+ Digest::CRC5#update 1.486578 0.000011 1.486589 ( 1.493215)
146
+ Digest::CRC8#update 1.261386 0.000000 1.261386 ( 1.266399)
147
+ Digest::CRC8_1Wire#update 1.250344 0.000000 1.250344 ( 1.255009)
148
+ Digest::CRC15#update 1.482515 0.000000 1.482515 ( 1.488131)
149
+ Digest::CRC16#update 1.216744 0.000811 1.217555 ( 1.222228)
150
+ Digest::CRC16CCITT#update 1.480490 0.000000 1.480490 ( 1.486745)
151
+ Digest::CRC16DNP#update 1.200067 0.000000 1.200067 ( 1.204835)
152
+ Digest::CRC16Genibus#update 1.492910 0.000000 1.492910 ( 1.498923)
153
+ Digest::CRC16Modbus#update 1.217449 0.000003 1.217452 ( 1.222348)
154
+ Digest::CRC16QT#update 1.223311 0.000000 1.223311 ( 1.229211)
155
+ Digest::CRC16USB#update 1.233744 0.000000 1.233744 ( 1.238615)
156
+ Digest::CRC16X25#update 1.223077 0.000000 1.223077 ( 1.227607)
157
+ Digest::CRC16XModem#update 1.487674 0.000000 1.487674 ( 1.493316)
158
+ Digest::CRC16ZModem#update 1.484288 0.000000 1.484288 ( 1.490096)
159
+ Digest::CRC24#update 1.490272 0.000000 1.490272 ( 1.496027)
160
+ Digest::CRC32#update 1.225311 0.000000 1.225311 ( 1.230572)
161
+ Digest::CRC32BZip2#update 1.503096 0.000000 1.503096 ( 1.509202)
162
+ Digest::CRC32c#update 1.220390 0.000000 1.220390 ( 1.225487)
163
+ Digest::CRC32Jam#update 1.216066 0.000000 1.216066 ( 1.220591)
164
+ Digest::CRC32MPEG#update 1.486808 0.000000 1.486808 ( 1.492611)
165
+ Digest::CRC32POSIX#update 1.494508 0.000957 1.495465 ( 1.503262)
166
+ Digest::CRC32XFER#update 1.504802 0.005830 1.510632 ( 1.522066)
167
+ Digest::CRC64#update 3.260784 0.015674 3.276458 ( 3.310506)
168
+ Digest::CRC64Jones#update 3.195204 0.000000 3.195204 ( 3.213054)
169
+ Digest::CRC64XZ#update 3.173597 0.000000 3.173597 ( 3.190438)
170
+
171
+ ### Ruby 2.7.4 (C extensions)
172
+
173
+ $ bundle exec rake build:c_exts
174
+ ...
175
+ $ bundle exec ./benchmarks.rb
176
+ Loading Digest::CRC classes ...
177
+ Generating 1000 8Kb lengthed strings ...
178
+ Benchmarking Digest::CRC classes ...
179
+ user system total real
180
+ Digest::CRC1#update 0.443619 0.000007 0.443626 ( 0.446545)
181
+ Digest::CRC5#update 0.025134 0.000806 0.025940 ( 0.026129)
182
+ Digest::CRC8#update 0.022564 0.000000 0.022564 ( 0.022775)
183
+ Digest::CRC8_1Wire#update 0.021427 0.000008 0.021435 ( 0.021551)
184
+ Digest::CRC15#update 0.030377 0.000833 0.031210 ( 0.031406)
185
+ Digest::CRC16#update 0.024004 0.000002 0.024006 ( 0.024418)
186
+ Digest::CRC16CCITT#update 0.026930 0.000001 0.026931 ( 0.027238)
187
+ Digest::CRC16DNP#update 0.024279 0.000000 0.024279 ( 0.024446)
188
+ Digest::CRC16Genibus#update 0.026477 0.000004 0.026481 ( 0.026656)
189
+ Digest::CRC16Modbus#update 0.023568 0.000000 0.023568 ( 0.023704)
190
+ Digest::CRC16QT#update 0.024161 0.000000 0.024161 ( 0.024316)
191
+ Digest::CRC16USB#update 0.023891 0.000000 0.023891 ( 0.024038)
192
+ Digest::CRC16X25#update 0.023849 0.000000 0.023849 ( 0.023991)
193
+ Digest::CRC16XModem#update 0.026254 0.000000 0.026254 ( 0.026523)
194
+ Digest::CRC16ZModem#update 0.026391 0.000000 0.026391 ( 0.026529)
195
+ Digest::CRC24#update 0.028805 0.000854 0.029659 ( 0.029830)
196
+ Digest::CRC32#update 0.024030 0.000000 0.024030 ( 0.024200)
197
+ Digest::CRC32BZip2#update 0.026942 0.000000 0.026942 ( 0.027244)
198
+ Digest::CRC32c#update 0.023989 0.000000 0.023989 ( 0.024159)
199
+ Digest::CRC32Jam#update 0.023940 0.000000 0.023940 ( 0.024066)
200
+ Digest::CRC32MPEG#update 0.027063 0.000000 0.027063 ( 0.027213)
201
+ Digest::CRC32POSIX#update 0.027137 0.000000 0.027137 ( 0.028160)
202
+ Digest::CRC32XFER#update 0.026956 0.000002 0.026958 ( 0.027103)
203
+ Digest::CRC64#update 0.024222 0.000005 0.024227 ( 0.024796)
204
+ Digest::CRC64Jones#update 0.025331 0.000000 0.025331 ( 0.025789)
205
+ Digest::CRC64XZ#update 0.024131 0.000001 0.024132 ( 0.024348)
206
+
207
+ ### Ruby 3.0.2 (pure Ruby)
208
+
209
+ $ bundle exec rake clean
210
+ $ bundle exec ./benchmarks.rb
211
+ Loading Digest::CRC classes ...
212
+ Generating 1000 8Kb lengthed strings ...
213
+ Benchmarking Digest::CRC classes ...
214
+ user system total real
215
+ Digest::CRC1#update 0.331405 0.000002 0.331407 ( 0.333588)
216
+ Digest::CRC5#update 1.206847 0.000020 1.206867 ( 1.224072)
217
+ Digest::CRC8#update 1.018571 0.000000 1.018571 ( 1.023002)
218
+ Digest::CRC8_1Wire#update 1.018802 0.000000 1.018802 ( 1.023292)
219
+ Digest::CRC15#update 1.207586 0.000000 1.207586 ( 1.212691)
220
+ Digest::CRC16#update 1.032505 0.000965 1.033470 ( 1.040862)
221
+ Digest::CRC16CCITT#update 1.198079 0.000000 1.198079 ( 1.203134)
222
+ Digest::CRC16DNP#update 0.994582 0.000000 0.994582 ( 1.006520)
223
+ Digest::CRC16Genibus#update 1.190596 0.000000 1.190596 ( 1.196087)
224
+ Digest::CRC16Modbus#update 1.007826 0.000000 1.007826 ( 1.012934)
225
+ Digest::CRC16QT#update 0.996298 0.000001 0.996299 ( 1.000255)
226
+ Digest::CRC16USB#update 0.995806 0.000000 0.995806 ( 0.999822)
227
+ Digest::CRC16X25#update 1.019589 0.000000 1.019589 ( 1.031010)
228
+ Digest::CRC16XModem#update 1.146947 0.000000 1.146947 ( 1.150817)
229
+ Digest::CRC16ZModem#update 1.145145 0.000000 1.145145 ( 1.149483)
230
+ Digest::CRC24#update 1.149009 0.000000 1.149009 ( 1.152854)
231
+ Digest::CRC32#update 0.970976 0.000000 0.970976 ( 0.974227)
232
+ Digest::CRC32BZip2#update 1.148596 0.000000 1.148596 ( 1.152381)
233
+ Digest::CRC32c#update 0.972566 0.000000 0.972566 ( 0.975790)
234
+ Digest::CRC32Jam#update 0.975854 0.000000 0.975854 ( 0.979217)
235
+ Digest::CRC32MPEG#update 1.148578 0.000000 1.148578 ( 1.153088)
236
+ Digest::CRC32POSIX#update 1.146218 0.000986 1.147204 ( 1.152460)
237
+ Digest::CRC32XFER#update 1.149823 0.000000 1.149823 ( 1.153692)
238
+ Digest::CRC64#update 2.869948 0.000016 2.869964 ( 2.884261)
239
+ Digest::CRC64Jones#update 2.867662 0.000000 2.867662 ( 2.886559)
240
+ Digest::CRC64XZ#update 2.858847 0.000000 2.858847 ( 2.874058)
241
+
242
+ ### Ruby 3.0.2 (C extensions)
243
+
244
+ $ bundle exec rake build:c_exts
245
+ ...
246
+ $ bundle exec ./benchmarks.rb
247
+ Loading Digest::CRC classes ...
248
+ Generating 1000 8Kb lengthed strings ...
249
+ Benchmarking Digest::CRC classes ...
250
+ user system total real
251
+ Digest::CRC1#update 0.349055 0.000000 0.349055 ( 0.350454)
252
+ Digest::CRC5#update 0.023144 0.000000 0.023144 ( 0.023248)
253
+ Digest::CRC8#update 0.021378 0.000000 0.021378 ( 0.021522)
254
+ Digest::CRC8_1Wire#update 0.021019 0.000000 0.021019 ( 0.021145)
255
+ Digest::CRC15#update 0.030063 0.000003 0.030066 ( 0.030245)
256
+ Digest::CRC16#update 0.024395 0.000000 0.024395 ( 0.024572)
257
+ Digest::CRC16CCITT#update 0.026979 0.000000 0.026979 ( 0.027138)
258
+ Digest::CRC16DNP#update 0.024665 0.000000 0.024665 ( 0.024844)
259
+ Digest::CRC16Genibus#update 0.027054 0.000000 0.027054 ( 0.027217)
260
+ Digest::CRC16Modbus#update 0.023963 0.000000 0.023963 ( 0.024257)
261
+ Digest::CRC16QT#update 0.024218 0.000000 0.024218 ( 0.024360)
262
+ Digest::CRC16USB#update 0.024393 0.000000 0.024393 ( 0.024561)
263
+ Digest::CRC16X25#update 0.025127 0.000000 0.025127 ( 0.025292)
264
+ Digest::CRC16XModem#update 0.028123 0.000000 0.028123 ( 0.028377)
265
+ Digest::CRC16ZModem#update 0.028205 0.000000 0.028205 ( 0.028571)
266
+ Digest::CRC24#update 0.031386 0.000000 0.031386 ( 0.031740)
267
+ Digest::CRC32#update 0.023832 0.000000 0.023832 ( 0.023948)
268
+ Digest::CRC32BZip2#update 0.027159 0.000000 0.027159 ( 0.027315)
269
+ Digest::CRC32c#update 0.024172 0.000000 0.024172 ( 0.024310)
270
+ Digest::CRC32Jam#update 0.024376 0.000000 0.024376 ( 0.024494)
271
+ Digest::CRC32MPEG#update 0.026035 0.000784 0.026819 ( 0.026940)
272
+ Digest::CRC32POSIX#update 0.026784 0.000000 0.026784 ( 0.026907)
273
+ Digest::CRC32XFER#update 0.026770 0.000000 0.026770 ( 0.026893)
274
+ Digest::CRC64#update 0.024400 0.000009 0.024409 ( 0.024531)
275
+ Digest::CRC64Jones#update 0.023477 0.000781 0.024258 ( 0.024390)
276
+ Digest::CRC64XZ#update 0.024611 0.000000 0.024611 ( 0.024779)
277
+
278
+ ### JRuby 9.2.18.0 (pure Ruby)
279
+
280
+ $ bundle exec ./benchmarks.rb
281
+ Loading Digest::CRC classes ...
282
+ Generating 1000 8Kb lengthed strings ...
283
+ Benchmarking Digest::CRC classes ...
284
+ user system total real
285
+ Digest::CRC1#update 1.080000 0.050000 1.130000 ( 0.676022)
286
+ Digest::CRC5#update 2.030000 0.040000 2.070000 ( 1.089240)
287
+ Digest::CRC8#update 1.590000 0.000000 1.590000 ( 0.999138)
288
+ Digest::CRC8_1Wire#update 0.920000 0.010000 0.930000 ( 0.873813)
289
+ Digest::CRC15#update 1.470000 0.030000 1.500000 ( 1.118886)
290
+ Digest::CRC16#update 1.780000 0.010000 1.790000 ( 1.067874)
291
+ Digest::CRC16CCITT#update 1.500000 0.070000 1.570000 ( 1.185564)
292
+ Digest::CRC16DNP#update 1.250000 0.000000 1.250000 ( 0.972322)
293
+ Digest::CRC16Genibus#update 1.700000 0.010000 1.710000 ( 1.092047)
294
+ Digest::CRC16Modbus#update 1.000000 0.010000 1.010000 ( 0.915328)
295
+ Digest::CRC16QT#update 1.250000 0.000000 1.250000 ( 0.968528)
296
+ Digest::CRC16USB#update 1.150000 0.010000 1.160000 ( 0.990387)
297
+ Digest::CRC16X25#update 0.940000 0.000000 0.940000 ( 0.926926)
298
+ Digest::CRC16XModem#update 1.390000 0.010000 1.400000 ( 1.100584)
299
+ Digest::CRC16ZModem#update 1.760000 0.020000 1.780000 ( 1.094003)
300
+ Digest::CRC24#update 1.690000 0.010000 1.700000 ( 1.106875)
301
+ Digest::CRC32#update 1.410000 0.020000 1.430000 ( 1.082506)
302
+ Digest::CRC32BZip2#update 1.510000 0.010000 1.520000 ( 1.104225)
303
+ Digest::CRC32c#update 1.270000 0.010000 1.280000 ( 1.023881)
304
+ Digest::CRC32Jam#update 1.190000 0.010000 1.200000 ( 0.998146)
305
+ Digest::CRC32MPEG#update 1.580000 0.010000 1.590000 ( 1.099086)
306
+ Digest::CRC32POSIX#update 1.550000 0.010000 1.560000 ( 1.142051)
307
+ Digest::CRC32XFER#update 1.360000 0.000000 1.360000 ( 1.071381)
308
+ Digest::CRC64#update 3.730000 0.020000 3.750000 ( 2.780390)
309
+ Digest::CRC64Jones#update 2.710000 0.020000 2.730000 ( 2.608007)
310
+ Digest::CRC64XZ#update 2.910000 0.020000 2.930000 ( 2.629401)
311
+
312
+ ### TruffleRuby 21.2.0 (pure Ruby)
313
+
314
+ $ bundle exec rake clean
315
+ $ bundle exec ./benchmarks.rb
316
+ Loading Digest::CRC classes ...
317
+ Generating 1000 8Kb lengthed strings ...
318
+ Benchmarking Digest::CRC classes ...
319
+ user system total real
320
+ Digest::CRC1#update 0.455340 0.000000 0.455340 ( 0.457710)
321
+ Digest::CRC5#update 1.406700 0.000000 1.406700 ( 1.412535)
322
+ Digest::CRC8#update 1.248323 0.000000 1.248323 ( 1.255452)
323
+ Digest::CRC8_1Wire#update 1.269434 0.000000 1.269434 ( 1.275315)
324
+ Digest::CRC15#update 1.428752 0.000000 1.428752 ( 1.434836)
325
+ Digest::CRC16#update 1.220394 0.000967 1.221361 ( 1.229684)
326
+ Digest::CRC16CCITT#update 1.434932 0.001000 1.435932 ( 1.452391)
327
+ Digest::CRC16DNP#update 1.191351 0.000000 1.191351 ( 1.202262)
328
+ Digest::CRC16Genibus#update 1.434067 0.000000 1.434067 ( 1.440300)
329
+ Digest::CRC16Modbus#update 1.200827 0.000000 1.200827 ( 1.205658)
330
+ Digest::CRC16QT#update 1.195077 0.000000 1.195077 ( 1.200328)
331
+ Digest::CRC16USB#update 1.196266 0.000000 1.196266 ( 1.201262)
332
+ Digest::CRC16X25#update 1.206690 0.000000 1.206690 ( 1.211781)
333
+ Digest::CRC16XModem#update 1.430468 0.000000 1.430468 ( 1.436801)
334
+ Digest::CRC16ZModem#update 1.442524 0.000000 1.442524 ( 1.448624)
335
+ Digest::CRC24#update 1.447611 0.000018 1.447629 ( 1.454534)
336
+ Digest::CRC32#update 1.214314 0.000000 1.214314 ( 1.219838)
337
+ Digest::CRC32BZip2#update 1.427408 0.000000 1.427408 ( 1.433626)
338
+ Digest::CRC32c#update 1.204985 0.000000 1.204985 ( 1.210273)
339
+ Digest::CRC32Jam#update 1.235039 0.000000 1.235039 ( 1.240686)
340
+ Digest::CRC32MPEG#update 1.429731 0.000000 1.429731 ( 1.435404)
341
+ Digest::CRC32POSIX#update 1.458886 0.000000 1.458886 ( 1.465914)
342
+ Digest::CRC32XFER#update 1.422109 0.000000 1.422109 ( 1.427635)
343
+ Digest::CRC64#update 3.283506 0.000000 3.283506 ( 3.303129)
344
+ Digest::CRC64Jones#update 3.297402 0.000000 3.297402 ( 3.317357)
345
+ Digest::CRC64XZ#update 3.278551 0.001875 3.280426 ( 3.315165)
346
+
347
+
348
+ ### TruffleRuby 21.2.0 (C extensions)
349
+
350
+ $ bundle exec rake build:c_exts
351
+ ...
352
+ $ bundle exec ./benchmarks.rb
353
+ Loading Digest::CRC classes ...
354
+ Generating 1000 8Kb lengthed strings ...
355
+ Benchmarking Digest::CRC classes ...
356
+ user system total real
357
+ Digest::CRC1#update 0.480586 0.000014 0.480600 ( 0.482817)
358
+ Digest::CRC5#update 0.023795 0.000000 0.023795 ( 0.023941)
359
+ Digest::CRC8#update 0.020619 0.000000 0.020619 ( 0.020747)
360
+ Digest::CRC8_1Wire#update 0.020571 0.000000 0.020571 ( 0.020700)
361
+ Digest::CRC15#update 0.031224 0.000000 0.031224 ( 0.031412)
362
+ Digest::CRC16#update 0.024013 0.000000 0.024013 ( 0.024174)
363
+ Digest::CRC16CCITT#update 0.026790 0.000000 0.026790 ( 0.027079)
364
+ Digest::CRC16DNP#update 0.024253 0.000000 0.024253 ( 0.024427)
365
+ Digest::CRC16Genibus#update 0.027237 0.000000 0.027237 ( 0.027390)
366
+ Digest::CRC16Modbus#update 0.024376 0.000000 0.024376 ( 0.024548)
367
+ Digest::CRC16QT#update 0.024361 0.000000 0.024361 ( 0.024518)
368
+ Digest::CRC16USB#update 0.024142 0.000000 0.024142 ( 0.024311)
369
+ Digest::CRC16X25#update 0.024098 0.000000 0.024098 ( 0.024222)
370
+ Digest::CRC16XModem#update 0.026306 0.000000 0.026306 ( 0.026502)
371
+ Digest::CRC16ZModem#update 0.026536 0.000000 0.026536 ( 0.026688)
372
+ Digest::CRC24#update 0.029732 0.000000 0.029732 ( 0.029902)
373
+ Digest::CRC32#update 0.024219 0.000000 0.024219 ( 0.024391)
374
+ Digest::CRC32BZip2#update 0.026817 0.000000 0.026817 ( 0.027044)
375
+ Digest::CRC32c#update 0.023681 0.000000 0.023681 ( 0.023798)
376
+ Digest::CRC32Jam#update 0.024243 0.000000 0.024243 ( 0.024419)
377
+ Digest::CRC32MPEG#update 0.026865 0.000000 0.026865 ( 0.027020)
378
+ Digest::CRC32POSIX#update 0.026583 0.000000 0.026583 ( 0.026748)
379
+ Digest::CRC32XFER#update 0.027423 0.000000 0.027423 ( 0.027615)
380
+ Digest::CRC64#update 0.024150 0.000000 0.024150 ( 0.024310)
381
+ Digest::CRC64Jones#update 0.024218 0.000000 0.024218 ( 0.024363)
382
+ Digest::CRC64XZ#update 0.024124 0.000000 0.024124 ( 0.024255)
383
+
384
+ ## Crystal
385
+
386
+ [crystal-crc] is a [Crystal][crystal-lang] port of this library.
387
+
388
+ [crystal-crc]: https://github.com/postmodern/crystal-crc
389
+ [crystal-lang]: https://www.crystal-lang.org/
390
+
391
+ ## Thanks
392
+
393
+ Special thanks go out to the [pycrc](http://www.tty1.net/pycrc/) library
394
+ which is able to generate C source-code for all of the CRC algorithms,
395
+ including their CRC Tables.
396
+
397
+ ## License
398
+
399
+ Copyright (c) 2010-2025 Hal Brodigan
400
+
401
+ See {file:LICENSE.txt} for license information.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError => e
6
+ abort e.message
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rubygems/tasks'
11
+ Gem::Tasks.new
12
+
13
+ namespace :build do
14
+ desc "Builds the C extensions"
15
+ task :c_exts do
16
+ Dir.chdir('ext/digest') { sh 'rake' }
17
+ end
18
+ end
19
+
20
+ require 'rake/clean'
21
+ CLEAN.include('ext/digest/crc*/extconf.h')
22
+ CLEAN.include('ext/digest/crc*/Makefile')
23
+ CLEAN.include('ext/digest/crc*/*.o')
24
+ CLEAN.include('ext/digest/crc*/*.so')
25
+
26
+ file 'spec/integration/docker/digest-crc.gem' do |t|
27
+ sh "gem build -o #{t.name} digest-crc.gemspec"
28
+ end
29
+
30
+ require 'rspec/core/rake_task'
31
+ namespace :spec do
32
+ RSpec::Core::RakeTask.new(:pure) do |t|
33
+ t.exclude_pattern = 'spec/integration/*_spec.rb'
34
+ end
35
+ task :pure => :clean
36
+
37
+ if RUBY_ENGINE == 'ruby'
38
+ RSpec::Core::RakeTask.new(:c_exts) do |t|
39
+ t.exclude_pattern = 'spec/integration/*_spec.rb'
40
+ end
41
+ task :c_exts
42
+ end
43
+
44
+ RSpec::Core::RakeTask.new(:integration) do |t|
45
+ t.pattern = 'spec/integration/*_spec.rb'
46
+ end
47
+ end
48
+
49
+ task :spec => 'spec:pure'
50
+ task :spec => 'spec:c_exts' if RUBY_ENGINE == 'ruby'
51
+
52
+ task :test => :spec
53
+ task :default => :spec
54
+
55
+ require 'yard'
56
+ YARD::Rake::YardocTask.new
57
+ task :doc => :yard
data/benchmarks.rb ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ require 'benchmark'
3
+ $LOAD_PATH.unshift(File.expand_path('../ext',__FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib',__FILE__))
5
+
6
+ CRCs = {
7
+ 'crc1' => 'CRC1',
8
+ 'crc5' => 'CRC5',
9
+ 'crc8' => 'CRC8',
10
+ 'crc8_1wire' => 'CRC81Wire',
11
+ 'crc15' => 'CRC15',
12
+ 'crc16' => 'CRC16',
13
+ 'crc16_ccitt' => 'CRC16CCITT',
14
+ 'crc16_dnp' => 'CRC16DNP',
15
+ 'crc16_genibus' => 'CRC16Genibus',
16
+ 'crc16_modbus' => 'CRC16Modbus',
17
+ 'crc16_qt' => 'CRC16QT',
18
+ 'crc16_usb' => 'CRC16USB',
19
+ 'crc16_x_25' => 'CRC16X25',
20
+ 'crc16_xmodem' => 'CRC16XModem',
21
+ 'crc16_zmodem' => 'CRC16ZModem',
22
+ 'crc24' => 'CRC24',
23
+ 'crc32' => 'CRC32',
24
+ 'crc32_bzip2' => 'CRC32BZip2',
25
+ 'crc32c' => 'CRC32c',
26
+ 'crc32_jam' => 'CRC32Jam',
27
+ 'crc32_mpeg' => 'CRC32Mpeg',
28
+ 'crc32_posix' => 'CRC32POSIX',
29
+ 'crc32_xfer' => 'CRC32XFER',
30
+ 'crc64' => 'CRC64',
31
+ 'crc64_jones' => 'CRC64Jones',
32
+ 'crc64_nvme' => 'CRC64NVMe',
33
+ 'crc64_xz' => 'CRC64XZ',
34
+ }
35
+
36
+ puts "Loading Digest::CRC classes ..."
37
+ CRCs.each_key { |crc| require "digest/#{crc}" }
38
+
39
+ N = 1000
40
+ BLOCK_SIZE = 8 * 1024
41
+
42
+ puts "Generating #{N} #{BLOCK_SIZE / 1024}Kb lengthed strings ..."
43
+ SAMPLES = Array.new(N) do
44
+ Array.new(BLOCK_SIZE) { rand(256).chr }.join
45
+ end
46
+
47
+ puts "Benchmarking Digest::CRC classes ..."
48
+ Benchmark.bm(27) do |b|
49
+ CRCs.each_value do |crc|
50
+ crc_class = Digest.const_get(crc)
51
+ crc = crc_class.new
52
+
53
+ b.report("#{crc_class}#update") do
54
+ SAMPLES.each do |sample|
55
+ crc.update(sample)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
7
+
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
+
13
+ require 'digest/crc/version'
14
+ Digest::CRC::VERSION
15
+ end
16
+
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
23
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
24
+
25
+ glob = ->(patterns) { gem.files & Dir[*patterns] }
26
+
27
+ gem.files = if gemspec['files'] then glob[gemspec['files']]
28
+ else `git ls-files`.split($/)
29
+ end
30
+
31
+ # exclude test files from the packages gem
32
+ gem.files -= glob[gemspec['test_files'] || 'spec/{**/}*']
33
+
34
+ gem.executables = gemspec.fetch('executables') do
35
+ glob['bin/*'].map { |path| File.basename(path) }
36
+ end
37
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
38
+
39
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
40
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
41
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
42
+
43
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
44
+ %w[ext lib].select { |dir| File.directory?(dir) }
45
+ })
46
+
47
+ gem.requirements = gemspec['requirements']
48
+ gem.required_ruby_version = gemspec['required_ruby_version']
49
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
50
+ gem.post_install_message = gemspec['post_install_message']
51
+
52
+ split = ->(string) { string.split(/,\s*/) }
53
+
54
+ if gemspec['dependencies']
55
+ gemspec['dependencies'].each do |name,versions|
56
+ gem.add_dependency(name,split[versions])
57
+ end
58
+ end
59
+
60
+ if gemspec['development_dependencies']
61
+ gemspec['development_dependencies'].each do |name,versions|
62
+ gem.add_development_dependency(name,split[versions])
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ def fail_gracefully(message)
2
+ warn "#{message}. Failing gracefully ..."
3
+ exit
4
+ end
5
+
6
+ unless RUBY_ENGINE == 'ruby'
7
+ fail_gracefully "C extensions for #{RUBY_ENGINE} currently not supported"
8
+ end
9
+
10
+ begin
11
+ require "mkmf"
12
+ rescue LoadError
13
+ fail_gracefully "mkmf is not installed"
14
+ end
15
+
16
+ CRCS = Dir['crc*']
17
+ DLEXT = MakeMakefile::CONFIG['DLEXT']
18
+
19
+ CRCS.each do |crc|
20
+ crc_ext = "#{crc}_ext"
21
+
22
+ file "#{crc}/Makefile" => "#{crc}/extconf.rb" do
23
+ Dir.chdir(crc) do
24
+ begin
25
+ ruby '-S', 'extconf.rb'
26
+ rescue
27
+ fail_gracefully "extconf.rb failed"
28
+ end
29
+ end
30
+ end
31
+
32
+ crc_ext_lib = "#{crc}_ext.#{DLEXT}"
33
+
34
+ file "#{crc}/#{crc_ext_lib}" => "#{crc}/Makefile" do
35
+ Dir.chdir(crc) do
36
+ begin
37
+ sh 'make', 'clean'
38
+ sh 'make'
39
+ rescue
40
+ fail_gracefully "Unable to build C extensions"
41
+ end
42
+ end
43
+ end
44
+
45
+ task :default => "#{crc}/#{crc_ext_lib}"
46
+ end
@@ -0,0 +1,11 @@
1
+ #ifndef _DIGEST_COMPAT_RUBY_H_
2
+ #define _DIGEST_COMPAT_RUBY_H_
3
+
4
+ #include <ruby.h>
5
+
6
+ // HACK: define USHORT2NUM for Ruby < 2.6
7
+ #ifndef USHORT2NUM
8
+ #define USHORT2NUM(x) RB_INT2FIX(x)
9
+ #endif
10
+
11
+ #endif