| 32 | namespace io { |
| 33 | |
| 34 | FileStream::FileStream(const std::string &path, bool append) |
| 35 | : logger_(logging::LoggerFactory<FileStream>::getLogger()), |
| 36 | path_(path), |
| 37 | offset_(0) { |
| 38 | file_stream_ = std::unique_ptr<std::fstream>(new std::fstream()); |
| 39 | if (append) { |
| 40 | file_stream_->open(path.c_str(), std::fstream::in | std::fstream::out | std::fstream::app | std::fstream::binary); |
| 41 | file_stream_->seekg(0, file_stream_->end); |
| 42 | file_stream_->seekp(0, file_stream_->end); |
| 43 | std::streamoff len = file_stream_->tellg(); |
| 44 | length_ = len > 0 ? gsl::narrow<size_t>(len) : 0; |
| 45 | seek(offset_); |
| 46 | } else { |
| 47 | file_stream_->open(path.c_str(), std::fstream::out | std::fstream::binary); |
| 48 | length_ = 0; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | FileStream::FileStream(const std::string &path, uint32_t offset, bool write_enable) |
| 53 | : logger_(logging::LoggerFactory<FileStream>::getLogger()), |