| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 "update_engine/decompressing_file_writer.h" | 5 #include "update_engine/decompressing_file_writer.h" |
| 6 | 6 |
| 7 namespace chromeos_update_engine { | 7 namespace chromeos_update_engine { |
| 8 | 8 |
| 9 // typedef struct z_stream_s { | 9 // typedef struct z_stream_s { |
| 10 // Bytef *next_in; /* next input byte */ | 10 // Bytef *next_in; /* next input byte */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 int GzipDecompressingFileWriter::Write(const void* bytes, size_t count) { | 30 int GzipDecompressingFileWriter::Write(const void* bytes, size_t count) { |
| 31 // Steps: | 31 // Steps: |
| 32 // put the data on next_in | 32 // put the data on next_in |
| 33 // call inflate until it returns nothing, each time writing what we get | 33 // call inflate until it returns nothing, each time writing what we get |
| 34 // check that next_in has no data left. | 34 // check that next_in has no data left. |
| 35 | 35 |
| 36 // It seems that zlib can keep internal buffers in the stream object, | 36 // It seems that zlib can keep internal buffers in the stream object, |
| 37 // so not all data we get fed to us this time will necessarily | 37 // so not all data we get fed to us this time will necessarily |
| 38 // be written out this time (in decompressed form). | 38 // be written out this time (in decompressed form). |
| 39 | 39 |
| 40 CHECK_EQ(0, stream_.avail_in); | 40 if (stream_.avail_in) { |
| 41 LOG(ERROR) << "Have data already. Bailing"; |
| 42 return -1; |
| 43 } |
| 41 char buf[1024]; | 44 char buf[1024]; |
| 42 | 45 |
| 43 buffer_.reserve(count); | 46 buffer_.reserve(count); |
| 44 buffer_.clear(); | 47 buffer_.clear(); |
| 45 CHECK_GE(buffer_.capacity(), count); | 48 CHECK_GE(buffer_.capacity(), count); |
| 46 const char* char_bytes = reinterpret_cast<const char*>(bytes); | 49 const char* char_bytes = reinterpret_cast<const char*>(bytes); |
| 47 buffer_.insert(buffer_.end(), char_bytes, char_bytes + count); | 50 buffer_.insert(buffer_.end(), char_bytes, char_bytes + count); |
| 48 | 51 |
| 49 stream_.next_in = reinterpret_cast<Bytef*>(&buffer_[0]); | 52 stream_.next_in = reinterpret_cast<Bytef*>(&buffer_[0]); |
| 50 stream_.avail_in = count; | 53 stream_.avail_in = count; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 // Inflate returned no data; we're done for now. Make sure no | 71 // Inflate returned no data; we're done for now. Make sure no |
| 69 // input data remain. | 72 // input data remain. |
| 70 CHECK_EQ(0, stream_.avail_in); | 73 CHECK_EQ(0, stream_.avail_in); |
| 71 break; | 74 break; |
| 72 } | 75 } |
| 73 } | 76 } |
| 74 return count; | 77 return count; |
| 75 } | 78 } |
| 76 | 79 |
| 77 } // namespace chromeos_update_engine | 80 } // namespace chromeos_update_engine |
| OLD | NEW |