blob: 341d1dff0038bfd6045834d2ebc1ab0523c29a71 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/vespalib/data/fileheader.h>
#include <memory>
class FastOS_FileInterface;
namespace search {
/**
* Class that encapsulates a file containing a generic file header, followed by binary data.
*
* After construction the file is positioned at the start of the binary data.
* It's assumed that the file was written using FileSettings::DIRECTIO_ALIGNMENT.
*/
class FileWithHeader {
private:
std::unique_ptr<FastOS_FileInterface> _file;
vespalib::FileHeader _header;
uint64_t _header_len;
uint64_t _file_size;
public:
FileWithHeader(std::unique_ptr<FastOS_FileInterface> file_in);
~FileWithHeader();
FastOS_FileInterface& file() const { return *_file; }
const vespalib::GenericHeader& header() const { return _header; }
uint64_t file_size() const { return _file_size; }
uint64_t data_size() const { return _file_size - _header_len; }
bool valid() const;
void rewind();
void close();
};
}
|