| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
|  | 16 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_XZ_EXTENT_WRITER_H_ | 
|  | 18 | #define UPDATE_ENGINE_PAYLOAD_CONSUMER_XZ_EXTENT_WRITER_H_ | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 19 |  | 
|  | 20 | #include <xz.h> | 
|  | 21 |  | 
|  | 22 | #include <memory> | 
| Amin Hassani | cd7edbe | 2017-09-18 17:05:02 -0700 | [diff] [blame] | 23 | #include <utility> | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 24 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 25 | #include <brillo/secure_blob.h> | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 26 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 27 | #include "update_engine/payload_consumer/extent_writer.h" | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | // XzExtentWriter is a concrete ExtentWriter subclass that xz-decompresses | 
|  | 30 | // what it's given in Write using xz-embedded. Note that xz-embedded only | 
|  | 31 | // supports files with either no CRC or CRC-32. It passes the decompressed data | 
|  | 32 | // to an underlying ExtentWriter. | 
|  | 33 |  | 
|  | 34 | namespace chromeos_update_engine { | 
|  | 35 |  | 
|  | 36 | class XzExtentWriter : public ExtentWriter { | 
|  | 37 | public: | 
|  | 38 | explicit XzExtentWriter(std::unique_ptr<ExtentWriter> underlying_writer) | 
|  | 39 | : underlying_writer_(std::move(underlying_writer)) {} | 
|  | 40 | ~XzExtentWriter() override; | 
|  | 41 |  | 
|  | 42 | bool Init(FileDescriptorPtr fd, | 
| Amin Hassani | cd7edbe | 2017-09-18 17:05:02 -0700 | [diff] [blame] | 43 | const google::protobuf::RepeatedPtrField<Extent>& extents, | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 44 | uint32_t block_size) override; | 
|  | 45 | bool Write(const void* bytes, size_t count) override; | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 46 |  | 
|  | 47 | private: | 
|  | 48 | // The underlying ExtentWriter. | 
|  | 49 | std::unique_ptr<ExtentWriter> underlying_writer_; | 
|  | 50 | // The opaque xz decompressor struct. | 
|  | 51 | xz_dec* stream_{nullptr}; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 52 | brillo::Blob input_buffer_; | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 53 |  | 
|  | 54 | DISALLOW_COPY_AND_ASSIGN(XzExtentWriter); | 
|  | 55 | }; | 
|  | 56 |  | 
|  | 57 | }  // namespace chromeos_update_engine | 
|  | 58 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 59 | #endif  // UPDATE_ENGINE_PAYLOAD_CONSUMER_XZ_EXTENT_WRITER_H_ |