aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/io/gzip_stream.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/io/gzip_stream.cc')
-rw-r--r--src/google/protobuf/io/gzip_stream.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/google/protobuf/io/gzip_stream.cc b/src/google/protobuf/io/gzip_stream.cc
index ee286961..e6037863 100644
--- a/src/google/protobuf/io/gzip_stream.cc
+++ b/src/google/protobuf/io/gzip_stream.cc
@@ -48,7 +48,7 @@ static const int kDefaultBufferSize = 65536;
GzipInputStream::GzipInputStream(
ZeroCopyInputStream* sub_stream, Format format, int buffer_size)
- : format_(format), sub_stream_(sub_stream), zerror_(Z_OK) {
+ : format_(format), sub_stream_(sub_stream), zerror_(Z_OK), byte_count_(0) {
zcontext_.zalloc = Z_NULL;
zcontext_.zfree = Z_NULL;
zcontext_.opaque = Z_NULL;
@@ -134,6 +134,7 @@ bool GzipInputStream::Next(const void** data, int* size) {
if (zcontext_.next_out != NULL) {
// sub_stream_ may have concatenated streams to follow
zerror_ = inflateEnd(&zcontext_);
+ byte_count_ += zcontext_.total_out;
if (zerror_ != Z_OK) {
return false;
}
@@ -178,8 +179,12 @@ bool GzipInputStream::Skip(int count) {
return ok;
}
int64 GzipInputStream::ByteCount() const {
- return zcontext_.total_out +
- (((uintptr_t)zcontext_.next_out) - ((uintptr_t)output_position_));
+ int64 ret = byte_count_ + zcontext_.total_out;
+ if (zcontext_.next_out != NULL && output_position_ != NULL) {
+ ret += reinterpret_cast<uintptr_t>(zcontext_.next_out) -
+ reinterpret_cast<uintptr_t>(output_position_);
+ }
+ return ret;
}
// =========================================================================