| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/compression/compression_utils.h" | 5 #include "components/compression/compression_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 #include <string.h> |
| 10 |
| 7 #include <vector> | 11 #include <vector> |
| 8 | 12 |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/logging.h" | 13 #include "base/logging.h" |
| 11 #include "base/sys_byteorder.h" | 14 #include "base/sys_byteorder.h" |
| 12 #include "third_party/zlib/zlib.h" | 15 #include "third_party/zlib/zlib.h" |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 // The difference in bytes between a zlib header and a gzip header. | 19 // The difference in bytes between a zlib header and a gzip header. |
| 17 const size_t kGzipZlibHeaderDifferenceBytes = 16; | 20 const size_t kGzipZlibHeaderDifferenceBytes = 16; |
| 18 | 21 |
| 19 // Pass an integer greater than the following get a gzip header instead of a | 22 // Pass an integer greater than the following get a gzip header instead of a |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 return Z_DATA_ERROR; | 107 return Z_DATA_ERROR; |
| 105 return err; | 108 return err; |
| 106 } | 109 } |
| 107 *dest_length = stream.total_out; | 110 *dest_length = stream.total_out; |
| 108 | 111 |
| 109 err = inflateEnd(&stream); | 112 err = inflateEnd(&stream); |
| 110 return err; | 113 return err; |
| 111 } | 114 } |
| 112 | 115 |
| 113 // Returns the uncompressed size from GZIP-compressed |compressed_data|. | 116 // Returns the uncompressed size from GZIP-compressed |compressed_data|. |
| 114 uint32 GetUncompressedSize(const std::string& compressed_data) { | 117 uint32_t GetUncompressedSize(const std::string& compressed_data) { |
| 115 // The uncompressed size is stored in the last 4 bytes of |input| in LE. | 118 // The uncompressed size is stored in the last 4 bytes of |input| in LE. |
| 116 uint32 size; | 119 uint32_t size; |
| 117 if (compressed_data.length() < sizeof(size)) | 120 if (compressed_data.length() < sizeof(size)) |
| 118 return 0; | 121 return 0; |
| 119 memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)], | 122 memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)], |
| 120 sizeof(size)); | 123 sizeof(size)); |
| 121 return base::ByteSwapToLE32(size); | 124 return base::ByteSwapToLE32(size); |
| 122 } | 125 } |
| 123 | 126 |
| 124 } // namespace | 127 } // namespace |
| 125 | 128 |
| 126 namespace compression { | 129 namespace compression { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 152 &uncompressed_size, | 155 &uncompressed_size, |
| 153 bit_cast<const Bytef*>(input.data()), | 156 bit_cast<const Bytef*>(input.data()), |
| 154 static_cast<uLongf>(input.length())) == Z_OK) { | 157 static_cast<uLongf>(input.length())) == Z_OK) { |
| 155 output->swap(uncompressed_output); | 158 output->swap(uncompressed_output); |
| 156 return true; | 159 return true; |
| 157 } | 160 } |
| 158 return false; | 161 return false; |
| 159 } | 162 } |
| 160 | 163 |
| 161 } // namespace compression | 164 } // namespace compression |
| OLD | NEW |