17 const std::string &tmp_dir)
23 const std::string &tmp_dir) :
24 in_memory_threshold_(in_memory_threshold),
43 int retval = fclose(
fp_);
75 buf_ =
reinterpret_cast<unsigned char *
>(smalloc(len));
79 buf_ =
reinterpret_cast<unsigned char *
>(srealloc(
buf_, newsize));
87 uint64_t bytes_written = fwrite(source, 1, len,
fp_);
88 if (bytes_written != len) {
90 "actually written %lu, error %d",
102 int retval = fclose(
fp_);
113 buf_ =
reinterpret_cast<unsigned char *
>(srealloc(
buf_,
pos_));
124 int64_t actual_len = (pos + len <=
size_) ?
125 len : static_cast<int64_t>(
size_) -
static_cast<int64_t
>(pos);
137 int64_t bytes_read =
ReadP(ptr, len,
pos_);
144 int64_t bytes_read =
Data(&source, len, pos);
145 memcpy(ptr, source, bytes_read);
170 uint64_t bytes_written = fwrite(
buf_, 1,
pos_,
fp_);
171 if (bytes_written !=
pos_) {
173 "actually written %lu, error %d",
static FileBackedBuffer * Create(uint64_t in_memory_threshold, const std::string &tmp_dir="/tmp/")
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
const uint64_t in_memory_threshold_
assert((mem||(size==0))&&"Out Of Memory")
MemoryMappedFile * mmapped_
enum FileBackedBuffer::@4 state_
int64_t ReadP(void *ptr, int64_t len, uint64_t pos)
int64_t Data(void **ptr, int64_t len, uint64_t pos)
int64_t Read(void *ptr, int64_t len)
enum FileBackedBuffer::@5 mode_
void Append(const void *source, uint64_t len)
FileBackedBuffer(uint64_t in_memory_threshold, const std::string &tmp_dir)
const std::string tmp_dir_
unsigned char * buffer() const