Commit 15d575f9 authored by Adenilson Cavalcanti's avatar Adenilson Cavalcanti Committed by Commit Bot

Adding uncompressed size function

Missing functionality to be able to reuse portable helpers.

Change-Id: If38e5f2b44cff9fb5f1744a59961ee6902f847f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876760Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Reviewed-by: default avatarMike Klein <mtklein@chromium.org>
Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709081}
parent 4587f9fb
......@@ -109,14 +109,8 @@ bool GzipUncompress(base::StringPiece input, std::string* output) {
}
uint32_t GetUncompressedSize(base::StringPiece compressed_data) {
// The uncompressed size is stored in the last 4 bytes of |input| in LE.
uint32_t size;
if (compressed_data.length() < sizeof(size))
return 0;
memcpy(&size,
&compressed_data.data()[compressed_data.length() - sizeof(size)],
sizeof(size));
return base::ByteSwapToLE32(size);
return zlib_internal::GetUncompressedSize(
bit_cast<Bytef*>(compressed_data.data()), compressed_data.length());
}
} // namespace compression
......@@ -8,7 +8,6 @@
#include "third_party/zlib/google/compression_utils_portable.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
......@@ -33,6 +32,21 @@ uLongf GZipExpectedCompressedSize(uLongf input_size) {
return kGzipZlibHeaderDifferenceBytes + compressBound(input_size);
}
// The expected decompressed size is stored in the last
// 4 bytes of |input| in LE.
uint32_t GetUncompressedSize(Bytef* compressed_data, size_t length) {
uint32_t size;
if (length < sizeof(size))
return 0;
memcpy(&size, &compressed_data[length - sizeof(size)], sizeof(size));
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return size;
#else
return __builtin_bswap32(size);
#endif
}
// This code is taken almost verbatim from third_party/zlib/compress.c. The only
// difference is deflateInit2() is called which sets the window bits to be > 16.
// That causes a gzip header to be emitted rather than a zlib header.
......
......@@ -7,6 +7,8 @@
#ifndef THIRD_PARTY_ZLIB_GOOGLE_COMPRESSION_UTILS_PORTABLE_H_
#define THIRD_PARTY_ZLIB_GOOGLE_COMPRESSION_UTILS_PORTABLE_H_
#include <stdint.h>
#if defined(USE_SYSTEM_ZLIB)
#include <zlib.h>
#else
......@@ -17,6 +19,8 @@ namespace zlib_internal {
uLongf GZipExpectedCompressedSize(uLongf input_size);
uint32_t GetUncompressedSize(Bytef* compressed_data, size_t length);
int GzipCompressHelper(Bytef* dest,
uLongf* dest_length,
const Bytef* source,
......@@ -28,6 +32,7 @@ int GzipUncompressHelper(Bytef* dest,
uLongf* dest_length,
const Bytef* source,
uLong source_length);
} // namespace zlib_internal
#endif // THIRD_PARTY_ZLIB_GOOGLE_COMPRESSION_UTILS_PORTABLE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment