28 std::shared_ptr<TOC> toc;
29 std::fstream writeStream;
30 const std::string filepath;
32 void allocFile(
long sizeInBytes)
const
35 throw std::invalid_argument(
"Cannot allocate negative sized file. "
36 "Size requested is " +
37 std::to_string(sizeInBytes));
39 std::ostringstream oss;
41 oss <<
"fallocate -l " << sizeInBytes <<
" " << filepath;
43 oss <<
"mkfile -n " << sizeInBytes <<
" " << filepath;
45 throw std::logic_error(
"Unsupported system (not __APPLE__ or __linux__).");
49 std::system(oss.str().c_str());
51 std::ifstream test(filepath, std::ios::ate);
52 long actualFileSize = test.tellg();
53 if (actualFileSize != sizeInBytes) {
54 std::ostringstream err_msg;
55 err_msg <<
"Could not allocate file '" << filepath
56 <<
"'.\nRequested size " << sizeInBytes <<
", actual size "
58 throw std::runtime_error(err_msg.str());
67 long recordSizeInBytes) :
69 toc(std::make_shared<
TOC>(rows, cols)),
73 const long tocSize = toc->memorySize();
74 const long fileSize = (cols * rows * recordSizeInBytes) + tocSize;
78 for (uint64_t j = 0; j < cols; ++j)
79 for (uint64_t i = 0; i < rows; ++i)
80 toc->setIdx(i, j, (i + j * rows) * recordSizeInBytes + tocSize);
83 writeStream.open(fpath, std::ios::in | std::ios::out | std::ios::binary);
84 if (!writeStream.is_open())
85 throw std::runtime_error(
"Could not open '" + fpath +
86 "' for writing out TOC.");
88 toc->write(writeStream);
94 writeStream(other.filepath,
95 std::ios::in | std::ios::out | std::ios::binary),
96 filepath(other.filepath)
98 if (!writeStream.is_open())
99 throw std::runtime_error(
"Could not open file '" + other.filepath +
100 "' for copied Writer.");
105 writeStream.seekp(toc->getIdx(row, col));
106 data.write(writeStream);