版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. # crc32
  2. Standard CRC-32 algorithm implementation in JS (for the browser and nodejs).
  3. Emphasis on correctness, performance, and IE6+ support.
  4. ## Installation
  5. With [npm](https://www.npmjs.org/package/crc-32):
  6. ```bash
  7. $ npm install crc-32
  8. ```
  9. When installed globally, npm installs a script `crc32` that computes the
  10. checksum for a specified file or standard input.
  11. <details>
  12. <summary><b>CDN Availability</b> (click to show)</summary>
  13. | CDN | URL |
  14. |-----------:|:-------------------------------------------|
  15. | `unpkg` | <https://unpkg.com/crc-32/> |
  16. | `jsDelivr` | <https://jsdelivr.com/package/npm/crc-32> |
  17. | `CDNjs` | <https://cdnjs.com/libraries/crc-32> |
  18. </details>
  19. ## Integration
  20. Using NodeJS or a bundler:
  21. ```js
  22. var CRC32 = require("crc-32");
  23. ```
  24. In the browser, the `crc32.js` script can be loaded directly:
  25. ```html
  26. <script src="crc32.js"></script>
  27. ```
  28. The browser script exposes a variable `CRC32`.
  29. The script will manipulate `module.exports` if available . This is not always
  30. desirable. To prevent the behavior, define `DO_NOT_EXPORT_CRC`.
  31. ### CRC32C (Castagnoli)
  32. The module and CDNs also include a parallel script for CRC32C calculations.
  33. Using NodeJS or a bundler:
  34. ```js
  35. var CRC32C = require("crc-32/crc32c");
  36. ```
  37. In the browser, the `crc32c.js` script can be loaded directly:
  38. ```html
  39. <script src="crc32c.js"></script>
  40. ```
  41. The browser exposes a variable `CRC32C`.
  42. The script will manipulate `module.exports` if available . This is not always
  43. desirable. To prevent the behavior, define `DO_NOT_EXPORT_CRC`.
  44. ## Usage
  45. In all cases, the relevant function takes an argument representing data and an
  46. optional second argument representing the starting "seed" (for rolling CRC).
  47. The return value is a signed 32-bit integer.
  48. - `CRC32.buf(byte array or buffer[, seed])` assumes the argument is a sequence
  49. of 8-bit unsigned integers (nodejs `Buffer`, `Uint8Array` or array of bytes).
  50. - `CRC32.bstr(binary string[, seed])` assumes the argument is a binary string
  51. where byte `i` is the low byte of the UCS-2 char: `str.charCodeAt(i) & 0xFF`
  52. - `CRC32.str(string[, seed])` assumes the argument is a standard JS string and
  53. calculates the hash of the UTF-8 encoding.
  54. For example:
  55. ```js
  56. // var CRC32 = require('crc-32'); // uncomment this line if in node
  57. CRC32.str("SheetJS") // -1647298270
  58. CRC32.bstr("SheetJS") // -1647298270
  59. CRC32.buf([ 83, 104, 101, 101, 116, 74, 83 ]) // -1647298270
  60. crc32 = CRC32.buf([83, 104]) // -1826163454 "Sh"
  61. crc32 = CRC32.str("eet", crc32) // 1191034598 "Sheet"
  62. CRC32.bstr("JS", crc32) // -1647298270 "SheetJS"
  63. [CRC32.str("\u2603"), CRC32.str("\u0003")] // [ -1743909036, 1259060791 ]
  64. [CRC32.bstr("\u2603"), CRC32.bstr("\u0003")] // [ 1259060791, 1259060791 ]
  65. [CRC32.buf([0x2603]), CRC32.buf([0x0003])] // [ 1259060791, 1259060791 ]
  66. // var CRC32C = require('crc-32/crc32c'); // uncomment this line if in node
  67. CRC32C.str("SheetJS") // -284764294
  68. CRC32C.bstr("SheetJS") // -284764294
  69. CRC32C.buf([ 83, 104, 101, 101, 116, 74, 83 ]) // -284764294
  70. crc32c = CRC32C.buf([83, 104]) // -297065629 "Sh"
  71. crc32c = CRC32C.str("eet", crc32c) // 1241364256 "Sheet"
  72. CRC32C.bstr("JS", crc32c) // -284764294 "SheetJS"
  73. [CRC32C.str("\u2603"), CRC32C.str("\u0003")] // [ 1253703093, 1093509285 ]
  74. [CRC32C.bstr("\u2603"), CRC32C.bstr("\u0003")] // [ 1093509285, 1093509285 ]
  75. [CRC32C.buf([0x2603]), CRC32C.buf([0x0003])] // [ 1093509285, 1093509285 ]
  76. ```
  77. ### Best Practices
  78. Even though the initial seed is optional, for performance reasons it is highly
  79. recommended to explicitly pass the default seed 0.
  80. In NodeJS with the native Buffer implementation, it is oftentimes faster to
  81. convert binary strings with `Buffer.from(bstr, "binary")` first:
  82. ```js
  83. /* Frequently slower in NodeJS */
  84. crc32 = CRC32.bstr(bstr, 0);
  85. /* Frequently faster in NodeJS */
  86. crc32 = CRC32.buf(Buffer.from(bstr, "binary"), 0);
  87. ```
  88. This does not apply to browser `Buffer` shims, and thus is not implemented in
  89. the library directly.
  90. ## Testing
  91. `make test` will run the nodejs-based test.
  92. To run the in-browser tests, run a local server and go to the `ctest` directory.
  93. `make ctestserv` will start a python `SimpleHTTPServer` server on port 8000.
  94. To update the browser artifacts, run `make ctest`.
  95. To generate the bits file, use the `crc32` function from python `zlib`:
  96. ```python
  97. >>> from zlib import crc32
  98. >>> x="foo bar baz٪☃🍣"
  99. >>> crc32(x)
  100. 1531648243
  101. >>> crc32(x+x)
  102. -218791105
  103. >>> crc32(x+x+x)
  104. 1834240887
  105. ```
  106. The included `crc32.njs` script can process files or standard input:
  107. ```bash
  108. $ echo "this is a test" > t.txt
  109. $ bin/crc32.njs t.txt
  110. 1912935186
  111. ```
  112. For comparison, the included `crc32.py` script uses python `zlib`:
  113. ```bash
  114. $ bin/crc32.py t.txt
  115. 1912935186
  116. ```
  117. On OSX the command `cksum` generates unsigned CRC-32 with Algorithm 3:
  118. ```bash
  119. $ cksum -o 3 < IE8.Win7.For.Windows.VMware.zip
  120. 1891069052 4161613172
  121. $ crc32 --unsigned ~/Downloads/IE8.Win7.For.Windows.VMware.zip
  122. 1891069052
  123. ```
  124. ## Performance
  125. `make perf` will run algorithmic performance tests (which should justify certain
  126. decisions in the code).
  127. The [`adler-32` project](http://git.io/adler32) has more performance notes
  128. ## License
  129. Please consult the attached LICENSE file for details. All rights not explicitly
  130. granted by the Apache 2.0 license are reserved by the Original Author.
  131. ## Badges
  132. [![Sauce Test Status](https://saucelabs.com/browser-matrix/crc32.svg)](https://saucelabs.com/u/crc32)
  133. [![Build Status](https://travis-ci.org/SheetJS/js-crc32.svg?branch=master)](https://travis-ci.org/SheetJS/js-crc32)
  134. [![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-crc32/master.svg)](https://coveralls.io/r/SheetJS/js-crc32?branch=master)
  135. [![Dependencies Status](https://david-dm.org/sheetjs/js-crc32/status.svg)](https://david-dm.org/sheetjs/js-crc32)
  136. [![NPM Downloads](https://img.shields.io/npm/dt/crc-32.svg)](https://npmjs.org/package/crc-32)
  137. [![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/js-xlsx)](https://ghit.me/repo/sheetjs/js-xlsx)
  138. [![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-crc32?pixel)](https://github.com/SheetJS/js-crc32)