compression_utils.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef THIRD_PARTY_ZLIB_GOOGLE_COMPRESSION_UTILS_H_
  5. #define THIRD_PARTY_ZLIB_GOOGLE_COMPRESSION_UTILS_H_
  6. #include <string>
  7. #include "base/strings/string_piece.h"
  8. namespace compression {
  9. // Compresses the data in |input| using gzip, storing the result in
  10. // |output_buffer|, of size |output_buffer_size|. If the buffer is large enough
  11. // and compression succeeds, |compressed_size| points to the compressed data
  12. // size after the call.
  13. // |malloc_fn| and |free_fn| are pointers to malloc() and free()-like functions,
  14. // or nullptr to use the standard ones.
  15. // Returns true for success.
  16. bool GzipCompress(base::StringPiece input,
  17. char* output_buffer,
  18. size_t output_buffer_size,
  19. size_t* compressed_size,
  20. void* (*malloc_fn)(size_t),
  21. void (*free_fn)(void*));
  22. // Compresses the data in |input| using gzip, storing the result in |output|.
  23. // |input| and |output| are allowed to point to the same string (in-place
  24. // operation).
  25. // Returns true for success.
  26. bool GzipCompress(base::StringPiece input, std::string* output);
  27. // Uncompresses the data in |input| using gzip, storing the result in |output|.
  28. // |input| and |output| are allowed to be the same string (in-place operation).
  29. // Returns true for success.
  30. bool GzipUncompress(const std::string& input, std::string* output);
  31. // Like the above method, but uses base::StringPiece to avoid allocations if
  32. // needed. |output|'s size must be at least as large as the return value from
  33. // GetUncompressedSize.
  34. // Returns true for success.
  35. bool GzipUncompress(base::StringPiece input, base::StringPiece output);
  36. // Uncompresses the data in |input| using gzip, and writes the results to
  37. // |output|, which must NOT be the underlying string of |input|, and is resized
  38. // if necessary.
  39. // Returns true for success.
  40. bool GzipUncompress(base::StringPiece input, std::string* output);
  41. // Returns the uncompressed size from GZIP-compressed |compressed_data|.
  42. uint32_t GetUncompressedSize(base::StringPiece compressed_data);
  43. } // namespace compression
  44. #endif // THIRD_PARTY_ZLIB_GOOGLE_COMPRESSION_UTILS_H_