quachecksum32.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef QUACHECKSUM32_H
  2. #define QUACHECKSUM32_H
  3. /*
  4. Copyright (C) 2005-2014 Sergey A. Tachenov
  5. This file is part of QuaZIP.
  6. QuaZIP is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published by
  8. the Free Software Foundation, either version 2.1 of the License, or
  9. (at your option) any later version.
  10. QuaZIP is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
  16. See COPYING file for the full LGPL text.
  17. Original ZIP package is copyrighted by Gilles Vollant and contributors,
  18. see quazip/(un)zip.h files for details. Basically it's the zlib license.
  19. */
  20. #include <QByteArray>
  21. #include "quazip_global.h"
  22. /// Checksum interface.
  23. /** \class QuaChecksum32 quachecksum32.h <quazip/quachecksum32.h>
  24. * This is an interface for 32 bit checksums.
  25. * Classes implementing this interface can calcunate a certin
  26. * checksum in a single step:
  27. * \code
  28. * QChecksum32 *crc32 = new QuaCrc32();
  29. * rasoult = crc32->calculate(data);
  30. * \endcode
  31. * or by streaming the data:
  32. * \code
  33. * QChecksum32 *crc32 = new QuaCrc32();
  34. * while(!fileA.atEnd())
  35. * crc32->update(fileA.read(bufSize));
  36. * resoultA = crc32->value();
  37. * crc32->reset();
  38. * while(!fileB.atEnd())
  39. * crc32->update(fileB.read(bufSize));
  40. * resoultB = crc32->value();
  41. * \endcode
  42. */
  43. class QUAZIP_EXPORT QuaChecksum32
  44. {
  45. public:
  46. ///Calculates the checksum for data.
  47. /** \a data source data
  48. * \return data checksum
  49. *
  50. * This function has no efect on the value returned by value().
  51. */
  52. virtual quint32 calculate(const QByteArray &data) = 0;
  53. ///Resets the calculation on a checksun for a stream.
  54. virtual void reset() = 0;
  55. ///Updates the calculated checksum for the stream
  56. /** \a buf next portion of data from the stream
  57. */
  58. virtual void update(const QByteArray &buf) = 0;
  59. ///Value of the checksum calculated for the stream passed throw update().
  60. /** \return checksum
  61. */
  62. virtual quint32 value() = 0;
  63. };
  64. #endif //QUACHECKSUM32_H