digest-crc 0.4.0 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +24 -0
  4. data/ChangeLog.md +102 -0
  5. data/Gemfile +15 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +71 -17
  8. data/Rakefile +31 -23
  9. data/benchmarks.rb +58 -0
  10. data/digest-crc.gemspec +2 -1
  11. data/ext/digest/Rakefile +51 -0
  12. data/ext/digest/compat/ruby.h +11 -0
  13. data/ext/digest/crc12_3gpp/crc12_3gpp.c +66 -0
  14. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  15. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +27 -0
  16. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  17. data/ext/digest/crc15/crc15.c +53 -0
  18. data/ext/digest/crc15/crc15.h +11 -0
  19. data/ext/digest/crc15/crc15_ext.c +28 -0
  20. data/ext/digest/crc15/extconf.rb +7 -0
  21. data/ext/digest/crc16/crc16.c +69 -0
  22. data/ext/digest/crc16/crc16.h +11 -0
  23. data/ext/digest/crc16/crc16_ext.c +28 -0
  24. data/ext/digest/crc16/extconf.rb +7 -0
  25. data/ext/digest/crc16_ccitt/crc16_ccitt.c +69 -0
  26. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  27. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +28 -0
  28. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  29. data/ext/digest/crc16_dnp/crc16_dnp.c +53 -0
  30. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  31. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +28 -0
  32. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  33. data/ext/digest/crc16_genibus/crc16_genibus.c +69 -0
  34. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  35. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +28 -0
  36. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  37. data/ext/digest/crc16_kermit/crc16_kermit.c +69 -0
  38. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  39. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +28 -0
  40. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  41. data/ext/digest/crc16_modbus/crc16_modbus.c +69 -0
  42. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  43. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +28 -0
  44. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  45. data/ext/digest/crc16_usb/crc16_usb.c +69 -0
  46. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  47. data/ext/digest/crc16_usb/crc16_usb_ext.c +28 -0
  48. data/ext/digest/crc16_usb/extconf.rb +7 -0
  49. data/ext/digest/crc16_x_25/crc16_x_25.c +69 -0
  50. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  51. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +28 -0
  52. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  53. data/ext/digest/crc16_xmodem/crc16_xmodem.c +69 -0
  54. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  55. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +28 -0
  56. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  57. data/ext/digest/crc16_zmodem/crc16_zmodem.c +69 -0
  58. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  59. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +28 -0
  60. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  61. data/ext/digest/crc24/crc24.c +69 -0
  62. data/ext/digest/crc24/crc24.h +11 -0
  63. data/ext/digest/crc24/crc24_ext.c +27 -0
  64. data/ext/digest/crc24/extconf.rb +7 -0
  65. data/ext/digest/crc32/crc32.c +68 -0
  66. data/ext/digest/crc32/crc32.h +11 -0
  67. data/ext/digest/crc32/crc32_ext.c +27 -0
  68. data/ext/digest/crc32/extconf.rb +7 -0
  69. data/ext/digest/crc32_bzip2/crc32_bzip2.c +69 -0
  70. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  71. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +27 -0
  72. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  73. data/ext/digest/crc32_jam/crc32_jam.c +69 -0
  74. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  75. data/ext/digest/crc32_jam/crc32_jam_ext.c +27 -0
  76. data/ext/digest/crc32_jam/extconf.rb +7 -0
  77. data/ext/digest/crc32_mpeg/crc32_mpeg.c +69 -0
  78. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  79. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +27 -0
  80. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  81. data/ext/digest/crc32_posix/crc32_posix.c +69 -0
  82. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  83. data/ext/digest/crc32_posix/crc32_posix_ext.c +27 -0
  84. data/ext/digest/crc32_posix/extconf.rb +7 -0
  85. data/ext/digest/crc32_xfer/crc32_xfer.c +69 -0
  86. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  87. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +27 -0
  88. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  89. data/ext/digest/crc32c/crc32c.c +69 -0
  90. data/ext/digest/crc32c/crc32c.h +8 -0
  91. data/ext/digest/crc32c/crc32c_ext.c +27 -0
  92. data/ext/digest/crc32c/extconf.rb +7 -0
  93. data/ext/digest/crc5/crc5.c +53 -0
  94. data/ext/digest/crc5/crc5.h +11 -0
  95. data/ext/digest/crc5/crc5_ext.c +27 -0
  96. data/ext/digest/crc5/extconf.rb +7 -0
  97. data/ext/digest/crc64/crc64.c +102 -0
  98. data/ext/digest/crc64/crc64.h +11 -0
  99. data/ext/digest/crc64/crc64_ext.c +27 -0
  100. data/ext/digest/crc64/extconf.rb +7 -0
  101. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  102. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  103. data/ext/digest/crc64_jones/crc64_jones_ext.c +27 -0
  104. data/ext/digest/crc64_jones/extconf.rb +7 -0
  105. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  106. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  107. data/ext/digest/crc64_xz/crc64_xz_ext.c +27 -0
  108. data/ext/digest/crc64_xz/extconf.rb +7 -0
  109. data/ext/digest/crc8/crc8.c +53 -0
  110. data/ext/digest/crc8/crc8.h +11 -0
  111. data/ext/digest/crc8/crc8_ext.c +27 -0
  112. data/ext/digest/crc8/extconf.rb +7 -0
  113. data/ext/digest/crc8_1wire/crc8_1wire.c +53 -0
  114. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  115. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +27 -0
  116. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  117. data/gemspec.yml +14 -6
  118. data/lib/digest/crc.rb +23 -7
  119. data/lib/digest/crc1.rb +0 -3
  120. data/lib/digest/crc15.rb +70 -0
  121. data/lib/digest/crc16.rb +6 -2
  122. data/lib/digest/crc16_ccitt.rb +7 -3
  123. data/lib/digest/crc16_dnp.rb +6 -2
  124. data/lib/digest/crc16_genibus.rb +72 -0
  125. data/lib/digest/crc16_kermit.rb +66 -0
  126. data/lib/digest/crc16_modbus.rb +5 -15
  127. data/lib/digest/crc16_qt.rb +11 -9
  128. data/lib/digest/crc16_usb.rb +4 -0
  129. data/lib/digest/crc16_x_25.rb +56 -0
  130. data/lib/digest/crc16_xmodem.rb +6 -2
  131. data/lib/digest/crc16_zmodem.rb +6 -2
  132. data/lib/digest/crc24.rb +6 -2
  133. data/lib/digest/crc32.rb +6 -2
  134. data/lib/digest/crc32_bzip2.rb +64 -0
  135. data/lib/digest/crc32_jam.rb +16 -0
  136. data/lib/digest/crc32_mpeg.rb +11 -3
  137. data/lib/digest/crc32_posix.rb +65 -0
  138. data/lib/digest/crc32_xfer.rb +68 -0
  139. data/lib/digest/crc32c.rb +5 -15
  140. data/lib/digest/crc5.rb +28 -2
  141. data/lib/digest/crc64.rb +6 -2
  142. data/lib/digest/crc64_jones.rb +88 -0
  143. data/lib/digest/crc64_xz.rb +90 -0
  144. data/lib/digest/crc8.rb +6 -2
  145. data/lib/digest/crc8_1wire.rb +9 -33
  146. data/spec/crc15_spec.rb +10 -0
  147. data/spec/crc16_genibus_spec.rb +10 -0
  148. data/spec/crc16_kermit_spec.rb +10 -0
  149. data/spec/crc16_x_25_spec.rb +10 -0
  150. data/spec/crc32_bzip2_spec.rb +10 -0
  151. data/spec/crc32_jam_spec.rb +10 -0
  152. data/spec/crc32_mpeg_spec.rb +7 -1
  153. data/spec/crc32_posix_spec.rb +10 -0
  154. data/spec/crc32_xfer_spec.rb +10 -0
  155. data/spec/crc64_jones_spec.rb +10 -0
  156. data/spec/crc64_xz_spec.rb +10 -0
  157. data/spec/crc8_1wire_spec.rb +7 -1
  158. data/spec/crc_examples.rb +3 -3
  159. data/spec/crc_spec.rb +63 -5
  160. data/spec/spec_helper.rb +0 -1
  161. metadata +151 -54
  162. data/.gemtest +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6f3a74146b25bc84927e5f441f7a31a23a4465aafeba993d7d9b0b390f81afde
4
+ data.tar.gz: d7a9d4dc7e435698dfc8e784464f16c1e2dbf394e93c6889bcaaf00fd3e1887e
5
+ SHA512:
6
+ metadata.gz: 4ba2b78693fb9af7e7eda4950fcf5d0e46d5c8ed6ad1469d1da444212396a2cf28308e97a055504cf0d04f0f1cfa6f192b2a4414ab9c6328a0d7a285048e5926
7
+ data.tar.gz: d04e97f73061f3617bab9d4371fb03463a2b366103ca4e4c8344a9b6d4ccb80e7919c76443cdb311a64a856c951980732e34289bab5fa69b3d3070aa3c8a4130
data/.gitignore CHANGED
@@ -1,4 +1,10 @@
1
+ Gemfile.lock
1
2
  doc
2
3
  pkg
3
4
  .bundle
4
5
  .yardoc
6
+ /ext/digest/crc*/Makefile
7
+ /ext/digest/crc*/mkmf.log
8
+ /ext/digest/crc*/extconf.h
9
+ /ext/digest/crc*/*.o
10
+ /ext/digest/crc*/*.so
@@ -0,0 +1,24 @@
1
+ ---
2
+ before_install:
3
+ - gem update --system
4
+ - gem install bundler -v "~> 2.0"
5
+
6
+ language: ruby
7
+ sudo: false
8
+ cache:
9
+ - bundler
10
+
11
+ rvm:
12
+ - 2.5
13
+ - 2.6
14
+ - 2.7
15
+ - jruby
16
+
17
+ matrix:
18
+ include:
19
+ - os: linux
20
+ - os: osx
21
+ allow_failures:
22
+ - rvm: jruby
23
+
24
+ script: bundle exec rake spec
@@ -1,3 +1,105 @@
1
+ ### 0.6.0 / 2020-06-16
2
+
3
+ * Implement _optional_ C extensions for all CRC algorithms, resulting in an
4
+ average performance improvement of ~40x. Note, if for whatever reason the
5
+ C extensions cannot be compiled, they will be skipped and the pure-Ruby
6
+ CRC algorithms will be used instead. If the C extensions were successfully
7
+ compiled, then they will be loaded and override the pure-Ruby CRC methods with
8
+ the C equivalents.
9
+
10
+ #### Pure Ruby
11
+
12
+ user system total real
13
+ Digest::CRC1#update 0.412953 0.000000 0.412953 ( 0.414688)
14
+ Digest::CRC5#update 1.116375 0.000003 1.116378 ( 1.120741)
15
+ Digest::CRC8#update 0.994263 0.000013 0.994276 ( 1.001079)
16
+ Digest::CRC8_1Wire#update 0.974115 0.000004 0.974119 ( 0.978186)
17
+ Digest::CRC15#update 1.139402 0.000927 1.140329 ( 1.146608)
18
+ Digest::CRC16#update 0.967836 0.000000 0.967836 ( 0.971792)
19
+ Digest::CRC16CCITT#update 1.118851 0.000000 1.118851 ( 1.123217)
20
+ Digest::CRC16DNP#update 0.922211 0.000000 0.922211 ( 0.925739)
21
+ Digest::CRC16Genibus#update 1.120580 0.000000 1.120580 ( 1.124771)
22
+ Digest::CRC16Modbus#update 0.955612 0.000000 0.955612 ( 0.959463)
23
+ Digest::CRC16QT#update 8.153403 0.000012 8.153415 ( 8.189977)
24
+ Digest::CRC16USB#update 0.952557 0.000000 0.952557 ( 0.956145)
25
+ Digest::CRC16X25#update 0.962295 0.000000 0.962295 ( 0.970401)
26
+ Digest::CRC16XModem#update 1.120531 0.000000 1.120531 ( 1.124494)
27
+ Digest::CRC16ZModem#update 1.124226 0.000000 1.124226 ( 1.128632)
28
+ Digest::CRC24#update 1.126317 0.000000 1.126317 ( 1.130794)
29
+ Digest::CRC32#update 0.960015 0.000000 0.960015 ( 0.964803)
30
+ Digest::CRC32BZip2#update 1.128626 0.000000 1.128626 ( 1.133641)
31
+ Digest::CRC32c#update 0.964047 0.000000 0.964047 ( 0.967456)
32
+ Digest::CRC32Jam#update 0.959141 0.000972 0.960113 ( 0.967444)
33
+ Digest::CRC32MPEG#update 1.131119 0.000002 1.131121 ( 1.137440)
34
+ Digest::CRC32POSIX#update 1.126019 0.000000 1.126019 ( 1.130549)
35
+ Digest::CRC32XFER#update 1.116598 0.000000 1.116598 ( 1.120595)
36
+ Digest::CRC64#update 2.665880 0.000928 2.666808 ( 2.680942)
37
+ Digest::CRC64Jones#update 2.678003 0.000000 2.678003 ( 2.691390)
38
+ Digest::CRC64XZ#update 2.671395 0.000000 2.671395 ( 2.682684)
39
+
40
+ #### C extensions
41
+
42
+ user system total real
43
+ Digest::CRC1#update 0.407438 0.000000 0.407438 ( 0.410495)
44
+ Digest::CRC5#update 0.022873 0.000000 0.022873 ( 0.023796)
45
+ Digest::CRC8#update 0.020129 0.000000 0.020129 ( 0.020887)
46
+ Digest::CRC8_1Wire#update 0.020106 0.000000 0.020106 ( 0.020897)
47
+ Digest::CRC15#update 0.028765 0.000003 0.028768 ( 0.029549)
48
+ Digest::CRC16#update 0.022176 0.000856 0.023032 ( 0.023153)
49
+ Digest::CRC16CCITT#update 0.028570 0.000000 0.028570 ( 0.028691)
50
+ Digest::CRC16DNP#update 0.023240 0.000001 0.023241 ( 0.024008)
51
+ Digest::CRC16Genibus#update 0.028692 0.000000 0.028692 ( 0.029575)
52
+ Digest::CRC16Modbus#update 0.023928 0.000000 0.023928 ( 0.024859)
53
+ Digest::CRC16QT#update 7.965822 0.000968 7.966790 ( 8.001781)
54
+ Digest::CRC16USB#update 0.023448 0.000001 0.023449 ( 0.024420)
55
+ Digest::CRC16X25#update 0.023061 0.000000 0.023061 ( 0.023861)
56
+ Digest::CRC16XModem#update 0.029407 0.000000 0.029407 ( 0.030583)
57
+ Digest::CRC16ZModem#update 0.029522 0.000000 0.029522 ( 0.030438)
58
+ Digest::CRC24#update 0.029528 0.000000 0.029528 ( 0.030504)
59
+ Digest::CRC32#update 0.023306 0.000000 0.023306 ( 0.024278)
60
+ Digest::CRC32BZip2#update 0.026346 0.000000 0.026346 ( 0.027293)
61
+ Digest::CRC32c#update 0.023525 0.000000 0.023525 ( 0.024489)
62
+ Digest::CRC32Jam#update 0.023348 0.000000 0.023348 ( 0.023477)
63
+ Digest::CRC32MPEG#update 0.026287 0.000000 0.026287 ( 0.027394)
64
+ Digest::CRC32POSIX#update 0.026063 0.000000 0.026063 ( 0.026986)
65
+ Digest::CRC32XFER#update 0.026374 0.000000 0.026374 ( 0.027314)
66
+ Digest::CRC64#update 0.023523 0.000000 0.023523 ( 0.024484)
67
+ Digest::CRC64Jones#update 0.023479 0.000000 0.023479 ( 0.024432)
68
+ Digest::CRC64XZ#update 0.024146 0.000000 0.024146 ( 0.025129)
69
+
70
+ ### 0.5.1 / 2020-03-03
71
+
72
+ * Fixed XOR logic in {Digest::CRC16Genibus}.
73
+ * Freeze all `TABLE` constants.
74
+ * Added missing documentation.
75
+
76
+ ### 0.5.0 / 2020-03-01
77
+
78
+ * Added {Digest::CRC15}.
79
+ * Added {Digest::CRC16Genibus}.
80
+ * Added {Digest::CRC16Kermit}.
81
+ * Added {Digest::CRC16X25}.
82
+ * Added {Digest::CRC32BZip2}.
83
+ * Added {Digest::CRC32Jam}.
84
+ * Added {Digest::CRC32POSIX}.
85
+ * Added {Digest::CRC32XFER}.
86
+ * Added {Digest::CRC64Jones}.
87
+ * Added {Digest::CRC64XZ}.
88
+ * Renamed `Digest::CRC32Mpeg` to {Digest::CRC32MPEG}.
89
+ * Renamed `Digest::CRC81Wire` to {Digest::CRC8_1Wire}.
90
+
91
+ ### 0.4.2 / 2020-03-01
92
+
93
+ * Corrected the logic in {Digest::CRC32#update}.
94
+ * Added missing {Digest::CRC5.pack} method.
95
+ * Fixed a require in `digest/crc8_1wire.rb`.
96
+
97
+ ### 0.4.1 / 2014-04-16
98
+
99
+ * Allow Digest CRC classes to be extended and their constants overriden.
100
+ * Allow {Digest::CRC5::CRC_MASK} to be overriden by subclasses.
101
+ * {Digest::CRC81Wire} now inherites from {Digest::CRC8}.
102
+
1
103
  ### 0.4.0 / 2013-02-13
2
104
 
3
105
  * Added {Digest::CRC16QT}.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+
9
+ gem 'rspec', '~> 3.0'
10
+
11
+ gem 'yard', '~> 0.9'
12
+ gem 'kramdown'
13
+ gem 'kramdown-parser-gfm'
14
+ gem 'github-markup', '~> 1.1'
15
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2013 Hal Brodigan
1
+ Copyright (c) 2010-2020 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Digest CRC
2
2
 
3
+ [![Build Status](https://travis-ci.org/postmodern/digest-crc.svg?branch=master)](https://travis-ci.org/postmodern/digest-crc)
4
+
3
5
  * [Source](https://github.com/postmodern/digest-crc)
4
6
  * [Issues](https://github.com/postmodern/digest-crc/issues)
5
7
  * [Documentation](http://rubydoc.info/gems/digest-crc/frames)
@@ -16,54 +18,106 @@ module.
16
18
  * {Digest::CRC1 CRC1}
17
19
  * {Digest::CRC5 CRC5}
18
20
  * {Digest::CRC8 CRC8}
19
- * {Digest::CRC81Wire CRC8 1-Wire}
21
+ * {Digest::CRC8_1Wire CRC8 1-Wire}
22
+ * {Digest::CRC15 CRC15}
20
23
  * {Digest::CRC16 CRC16}
21
24
  * {Digest::CRC16CCITT CRC16 CCITT}
22
25
  * {Digest::CRC16DNP CRC16 DNP}
26
+ * {Digest::CRC16Genibus CRC16 Genibus}
27
+ * {Digest::CRC16Kermit CRC16 Kermit}
23
28
  * {Digest::CRC16Modbus CRC16 Modbus}
24
29
  * {Digest::CRC16USB CRC16 USB}
30
+ * {Digest::CRC16X25 CRC16 X25}
25
31
  * {Digest::CRC16XModem CRC16 XModem}
26
32
  * {Digest::CRC16ZModem CRC16 ZModem}
27
33
  * {Digest::CRC16QT CRC16 QT}
28
34
  * {Digest::CRC24 CRC24}
29
35
  * {Digest::CRC32 CRC32}
36
+ * {Digest::CRC32BZip2 CRC32 BZip2}
30
37
  * {Digest::CRC32c CRC32c}
31
- * {Digest::CRC32Mpeg CRC32 Mpeg}
38
+ * {Digest::CRC32Jam CRC32 Jam}
39
+ * {Digest::CRC32MPEG CRC32 MPEG}
40
+ * {Digest::CRC32POSIX CRC32 POSIX}
41
+ * {Digest::CRC32XFER CRC32 XFER}
32
42
  * {Digest::CRC64 CRC64}
43
+ * {Digest::CRC64Jones CRC64 Jones}
44
+ * {Digest::CRC64XZ CRC64 XZ}
33
45
  * Pure Ruby implementation.
34
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.
35
50
 
36
51
  ## Install
37
52
 
38
- $ gem install digest-crc
53
+ ```
54
+ gem install digest-crc
55
+ ```
39
56
 
40
57
  ## Examples
41
58
 
42
59
  Calculate a CRC32:
43
60
 
44
- require 'digest/crc32'
61
+ ```ruby
62
+ require 'digest/crc32'
45
63
 
46
- Digest::CRC32.hexdigest('hello')
47
- # => "3610a686"
64
+ Digest::CRC32.hexdigest('hello')
65
+ # => "3610a686"
66
+ ```
48
67
 
49
68
  Calculate a CRC32 of a file:
50
69
 
51
- Digest::CRC32.file('README.md')
52
- # => #<Digest::CRC32: 127ad531>
70
+ ```ruby
71
+ Digest::CRC32.file('README.md')
72
+ # => #<Digest::CRC32: 127ad531>
73
+ ```
53
74
 
54
75
  Incrementally calculate a CRC32:
55
76
 
56
- crc = Digest::CRC32.new
57
- crc << 'one'
58
- crc << 'two'
59
- crc << 'three'
60
- crc.hexdigest
61
- # => "09e1c092"
77
+ ```ruby
78
+ crc = Digest::CRC32.new
79
+ crc << 'one'
80
+ crc << 'two'
81
+ crc << 'three'
82
+ crc.hexdigest
83
+ # => "09e1c092"
84
+ ```
62
85
 
63
86
  Directly access the checksum:
64
87
 
65
- crc.checksum
66
- # => 165789842
88
+ ```ruby
89
+ crc.checksum
90
+ # => 165789842
91
+ ```
92
+
93
+ Defining your own CRC class:
94
+
95
+ ```ruby
96
+ require 'digest/crc32'
97
+
98
+ module Digest
99
+ class CRC3000 < CRC32
100
+
101
+ WIDTH = 4
102
+
103
+ INIT_CRC = 0xffffffff
104
+
105
+ XOR_MASK = 0xffffffff
106
+
107
+ TABLE = [
108
+ # ....
109
+ ].freeze
110
+
111
+ def update(data)
112
+ data.each_byte do |b|
113
+ @crc = (((@crc >> 8) & 0x00ffffff) ^ @table[(@crc ^ b) & 0xff])
114
+ end
115
+
116
+ return self
117
+ end
118
+ end
119
+ end
120
+ ```
67
121
 
68
122
  ## Thanks
69
123
 
@@ -73,6 +127,6 @@ including their CRC Tables.
73
127
 
74
128
  ## License
75
129
 
76
- Copyright (c) 2010-2013 Hal Brodigan
130
+ Copyright (c) 2010-2020 Hal Brodigan
77
131
 
78
132
  See {file:LICENSE.txt} for license information.
data/Rakefile CHANGED
@@ -1,36 +1,44 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
2
 
4
3
  begin
5
- gem 'rubygems-tasks', '~> 0.1'
6
- require 'rubygems/tasks'
7
-
8
- Gem::Tasks.new
4
+ require 'bundler/setup'
9
5
  rescue LoadError => e
10
- warn e.message
11
- warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
6
+ abort e.message
12
7
  end
13
8
 
14
- begin
15
- gem 'rspec', '~> 2.4'
16
- require 'rspec/core/rake_task'
9
+ require 'rake'
10
+ require 'rubygems/tasks'
11
+ Gem::Tasks.new
17
12
 
18
- RSpec::Core::RakeTask.new
19
- rescue LoadError => e
20
- task :spec do
21
- abort "Please run `gem install rspec` to install RSpec."
13
+ namespace :build do
14
+ desc "Builds the C extensions"
15
+ task :c_exts do
16
+ Dir.chdir('ext/digest') { sh 'rake' }
22
17
  end
23
18
  end
24
- task :test => :spec
25
- task :default => :spec
26
19
 
27
- begin
28
- gem 'yard', '~> 0.8'
29
- require 'yard'
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')
30
25
 
31
- YARD::Rake::YardocTask.new
32
- rescue LoadError => e
33
- task :yard do
34
- abort "Please run `gem install yard` to install YARD."
26
+ require 'rspec/core/rake_task'
27
+ namespace :spec do
28
+ RSpec::Core::RakeTask.new(:pure)
29
+ task :pure => :clean
30
+
31
+ if RUBY_ENGINE == 'ruby'
32
+ RSpec::Core::RakeTask.new(:c_exts)
33
+ task :c_exts => 'build:c_exts'
35
34
  end
36
35
  end
36
+
37
+ task :spec => 'spec:pure'
38
+ task :spec => 'spec:c_exts' if RUBY_ENGINE == 'ruby'
39
+ task :test => :spec
40
+ task :default => :spec
41
+
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new
44
+ task :doc => :yard
@@ -0,0 +1,58 @@
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_xz' => 'CRC64XZ',
33
+ }
34
+
35
+ puts "Loading Digest::CRC classes ..."
36
+ CRCs.each_key { |crc| require "digest/#{crc}" }
37
+
38
+ N = 1000
39
+ BLOCK_SIZE = 8 * 1024
40
+
41
+ puts "Generating #{N} #{BLOCK_SIZE / 1024}Kb lengthed strings ..."
42
+ SAMPLES = Array.new(N) do
43
+ Array.new(BLOCK_SIZE) { rand(256).chr }.join
44
+ end
45
+
46
+ puts "Benchmarking Digest::CRC classes ..."
47
+ Benchmark.bm do |b|
48
+ CRCs.each_value do |crc|
49
+ crc_class = Digest.const_get(crc)
50
+ crc = crc_class.new
51
+
52
+ b.report("#{crc_class}#update") do
53
+ SAMPLES.each do |sample|
54
+ crc.update(sample)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
12
 
13
13
  require 'digest/crc/version'
14
- Digest::Crc::VERSION
14
+ Digest::CRC::VERSION
15
15
  end
16
16
 
17
17
  gem.summary = gemspec['summary']
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.authors = Array(gemspec['authors'])
21
21
  gem.email = gemspec['email']
22
22
  gem.homepage = gemspec['homepage']
23
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
23
24
 
24
25
  glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
26