Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/protobuf/src/google/protobuf/io/gzip_stream.cc

Issue 21208003: Update protobuf to r428, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/ 3 // http://code.google.com/p/protobuf/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 GzipOutputStream::GzipOutputStream(ZeroCopyOutputStream* sub_stream) { 193 GzipOutputStream::GzipOutputStream(ZeroCopyOutputStream* sub_stream) {
194 Init(sub_stream, Options()); 194 Init(sub_stream, Options());
195 } 195 }
196 196
197 GzipOutputStream::GzipOutputStream(ZeroCopyOutputStream* sub_stream, 197 GzipOutputStream::GzipOutputStream(ZeroCopyOutputStream* sub_stream,
198 const Options& options) { 198 const Options& options) {
199 Init(sub_stream, options); 199 Init(sub_stream, options);
200 } 200 }
201 201
202 GzipOutputStream::GzipOutputStream(
203 ZeroCopyOutputStream* sub_stream, Format format, int buffer_size) {
204 Options options;
205 options.format = format;
206 if (buffer_size != -1) {
207 options.buffer_size = buffer_size;
208 }
209 Init(sub_stream, options);
210 }
211
212 void GzipOutputStream::Init(ZeroCopyOutputStream* sub_stream, 202 void GzipOutputStream::Init(ZeroCopyOutputStream* sub_stream,
213 const Options& options) { 203 const Options& options) {
214 sub_stream_ = sub_stream; 204 sub_stream_ = sub_stream;
215 sub_data_ = NULL; 205 sub_data_ = NULL;
216 sub_data_size_ = 0; 206 sub_data_size_ = 0;
217 207
218 input_buffer_length_ = options.buffer_size; 208 input_buffer_length_ = options.buffer_size;
219 input_buffer_ = operator new(input_buffer_length_); 209 input_buffer_ = operator new(input_buffer_length_);
220 GOOGLE_CHECK(input_buffer_ != NULL); 210 GOOGLE_CHECK(input_buffer_ != NULL);
221 211
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 292 }
303 void GzipOutputStream::BackUp(int count) { 293 void GzipOutputStream::BackUp(int count) {
304 GOOGLE_CHECK_GE(zcontext_.avail_in, count); 294 GOOGLE_CHECK_GE(zcontext_.avail_in, count);
305 zcontext_.avail_in -= count; 295 zcontext_.avail_in -= count;
306 } 296 }
307 int64 GzipOutputStream::ByteCount() const { 297 int64 GzipOutputStream::ByteCount() const {
308 return zcontext_.total_in + zcontext_.avail_in; 298 return zcontext_.total_in + zcontext_.avail_in;
309 } 299 }
310 300
311 bool GzipOutputStream::Flush() { 301 bool GzipOutputStream::Flush() {
312 do { 302 zerror_ = Deflate(Z_FULL_FLUSH);
313 zerror_ = Deflate(Z_FULL_FLUSH); 303 // Return true if the flush succeeded or if it was a no-op.
314 } while (zerror_ == Z_OK); 304 return (zerror_ == Z_OK) ||
315 return zerror_ == Z_OK; 305 (zerror_ == Z_BUF_ERROR && zcontext_.avail_in == 0 &&
306 zcontext_.avail_out != 0);
316 } 307 }
317 308
318 bool GzipOutputStream::Close() { 309 bool GzipOutputStream::Close() {
319 if ((zerror_ != Z_OK) && (zerror_ != Z_BUF_ERROR)) { 310 if ((zerror_ != Z_OK) && (zerror_ != Z_BUF_ERROR)) {
320 return false; 311 return false;
321 } 312 }
322 do { 313 do {
323 zerror_ = Deflate(Z_FINISH); 314 zerror_ = Deflate(Z_FINISH);
324 } while (zerror_ == Z_OK); 315 } while (zerror_ == Z_OK);
325 zerror_ = deflateEnd(&zcontext_); 316 zerror_ = deflateEnd(&zcontext_);
326 bool ok = zerror_ == Z_OK; 317 bool ok = zerror_ == Z_OK;
327 zerror_ = Z_STREAM_END; 318 zerror_ = Z_STREAM_END;
328 return ok; 319 return ok;
329 } 320 }
330 321
331 } // namespace io 322 } // namespace io
332 } // namespace protobuf 323 } // namespace protobuf
333 } // namespace google 324 } // namespace google
334 325
335 #endif // HAVE_ZLIB 326 #endif // HAVE_ZLIB
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698