blob: ebec5221256446d39572ade8fb851077b1f5bbab [file] [log] [blame]
Sen Jiang716d5692016-05-09 16:43:34 -07001// 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
Alex Deymoddf9db52017-03-02 16:10:41 -080012#include "bsdiff/file_interface.h"
Sen Jiang716d5692016-05-09 16:43:34 -070013
14using sink_func = std::function<size_t(const uint8_t*, size_t)>;
15
16namespace bsdiff {
17
18class 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.
Amin Hassani8a183d32018-07-02 11:37:53 -070036 const sink_func sink_;
Sen Jiang716d5692016-05-09 16:43:34 -070037};
38
39} // namespace bsdiff
40
41#endif // _BSDIFF_SINK_FILE_H_