zlib.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. // This is a derivative work based on Zlib, copyright below:
  10. /*
  11. Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
  12. This software is provided 'as-is', without any express or implied
  13. warranty. In no event will the authors be held liable for any damages
  14. arising from the use of this software.
  15. Permission is granted to anyone to use this software for any purpose,
  16. including commercial applications, and to alter it and redistribute it
  17. freely, subject to the following restrictions:
  18. 1. The origin of this software must not be misrepresented; you must not
  19. claim that you wrote the original software. If you use this software
  20. in a product, an acknowledgment in the product documentation would be
  21. appreciated but is not required.
  22. 2. Altered source versions must be plainly marked as such, and must not be
  23. misrepresented as being the original software.
  24. 3. This notice may not be removed or altered from any source distribution.
  25. Jean-loup Gailly Mark Adler
  26. jloup@gzip.org madler@alumni.caltech.edu
  27. The data format used by the zlib library is described by RFCs (Request for
  28. Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
  29. (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
  30. */
  31. #ifndef BOOST_BEAST_ZLIB_ZLIB_HPP
  32. #define BOOST_BEAST_ZLIB_ZLIB_HPP
  33. #include <boost/beast/core/detail/config.hpp>
  34. #include <cstdint>
  35. #include <cstdlib>
  36. namespace boost {
  37. namespace beast {
  38. namespace zlib {
  39. #if !defined(__MACTYPES__)
  40. using Byte = unsigned char; // 8 bits
  41. #endif
  42. using uInt = unsigned int; // 16 bits or more
  43. /* Possible values of the data_type field (though see inflate()) */
  44. enum kind
  45. {
  46. binary = 0,
  47. text = 1,
  48. unknown = 2
  49. };
  50. /** Deflate codec parameters.
  51. Objects of this type are filled in by callers and provided to the
  52. deflate codec to define the input and output areas for the next
  53. compress or decompress operation.
  54. The application must update next_in and avail_in when avail_in has dropped
  55. to zero. It must update next_out and avail_out when avail_out has dropped
  56. to zero. The application must initialize zalloc, zfree and opaque before
  57. calling the init function. All other fields are set by the compression
  58. library and must not be updated by the application.
  59. The fields total_in and total_out can be used for statistics or progress
  60. reports. After compression, total_in holds the total size of the
  61. uncompressed data and may be saved for use in the decompressor (particularly
  62. if the decompressor wants to decompress everything in a single step).
  63. */
  64. struct z_params
  65. {
  66. /** A pointer to the next input byte.
  67. If there is no more input, this may be set to `nullptr`.
  68. */
  69. void const* next_in;
  70. /** The number of bytes of input available at `next_in`.
  71. If there is no more input, this should be set to zero.
  72. */
  73. std::size_t avail_in;
  74. /** The total number of input bytes read so far.
  75. */
  76. std::size_t total_in = 0;
  77. /** A pointer to the next output byte.
  78. */
  79. void* next_out;
  80. /** The remaining bytes of space at `next_out`.
  81. */
  82. std::size_t avail_out;
  83. /** The total number of bytes output so far.
  84. */
  85. std::size_t total_out = 0;
  86. int data_type = unknown; // best guess about the data type: binary or text
  87. };
  88. /** Flush option.
  89. */
  90. enum class Flush
  91. {
  92. // order matters
  93. none,
  94. block,
  95. partial,
  96. sync,
  97. full,
  98. finish,
  99. trees
  100. };
  101. /* compression levels */
  102. enum compression
  103. {
  104. none = 0,
  105. best_speed = 1,
  106. best_size = 9,
  107. default_size = -1
  108. };
  109. /** Compression strategy.
  110. These are used when compressing streams.
  111. */
  112. enum class Strategy
  113. {
  114. /** Default strategy.
  115. This is suitable for general purpose compression, and works
  116. well in the majority of cases.
  117. */
  118. normal,
  119. /** Filtered strategy.
  120. This strategy should be used when the data be compressed
  121. is produced by a filter or predictor.
  122. */
  123. filtered,
  124. /** Huffman-only strategy.
  125. This strategy only performs Huffman encoding, without doing
  126. any string matching.
  127. */
  128. huffman,
  129. /** Run Length Encoding strategy.
  130. This strategy limits match distances to one, making it
  131. equivalent to run length encoding. This can give better
  132. performance for things like PNG image data.
  133. */
  134. rle,
  135. /** Fixed table strategy.
  136. This strategy prevents the use of dynamic Huffman codes,
  137. allowing for a simpler decoder for special applications.
  138. */
  139. fixed
  140. };
  141. } // zlib
  142. } // beast
  143. } // boost
  144. #endif