1 // Copyright 2016 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef _BSDIFF_SINK_FILE_H_ 6 #define _BSDIFF_SINK_FILE_H_ 7 8 #include <stdint.h> 9 10 #include <functional> 11 12 #include "bsdiff/file_interface.h" 13 14 using sink_func = std::function<size_t(const uint8_t*, size_t)>; 15 16 namespace bsdiff { 17 18 class SinkFile : public FileInterface { 19 public: 20 // Creates a SinkFile based on the underlying |sink| function passed. 21 // The SinkFile will call |sink| function upon write. 22 // Read, Seek and GetSize are not supported. 23 explicit SinkFile(const sink_func& sink); 24 25 ~SinkFile() = default; 26 27 // FileInterface overrides. 28 bool Read(void* buf, size_t count, size_t* bytes_read) override; 29 bool Write(const void* buf, size_t count, size_t* bytes_written) override; 30 bool Seek(off_t pos) override; 31 bool Close() override; 32 bool GetSize(uint64_t* size) override; 33 34 private: 35 // The sink() function used to write data. 36 const sink_func sink_; 37 }; 38 39 } // namespace bsdiff 40 41 #endif // _BSDIFF_SINK_FILE_H_ 42