mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 17:37:47 +01:00
proper cmake
This commit is contained in:
51
src/repo/srcs/objects/FileBuffer.cpp
Normal file
51
src/repo/srcs/objects/FileBuffer.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by Stepan Usatiuk on 23.04.2023.
|
||||
//
|
||||
|
||||
#include "../../includes/objects/FileBuffer.h"
|
||||
|
||||
#include "../../includes/Serialize.h"
|
||||
|
||||
FileBuffer::FileBuffer(const Repository *repo, Object::idType fileId) : repo(repo), file(Serialize::deserialize<File>(repo->getObject(fileId))), chunksQueue() {
|
||||
for (auto const &id: file.chunks) chunksQueue.emplace(id);
|
||||
};
|
||||
|
||||
int FileBuffer::sync() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::streamsize FileBuffer::xsgetn(char *s, std::streamsize countr) {
|
||||
if (underflow() == std::char_traits<char>::eof()) return 0;
|
||||
for (int i = 0; i < countr; i++) {
|
||||
auto c = uflow();
|
||||
if (c != traits_type::eof()) {
|
||||
s[i] = traits_type::to_char_type(c);
|
||||
} else
|
||||
return i;
|
||||
}
|
||||
return countr;
|
||||
}
|
||||
|
||||
int FileBuffer::uflow() {
|
||||
auto out = underflow();
|
||||
if (out != traits_type::eof())
|
||||
curGetBufPos++;
|
||||
return out;
|
||||
}
|
||||
|
||||
int FileBuffer::underflow() {
|
||||
if (getBuf.empty() || curGetBufPos == getBuf.size()) {
|
||||
if (chunksQueue.empty()) return traits_type::eof();
|
||||
else {
|
||||
auto chunk = Serialize::deserialize<Chunk>(repo->getObject(chunksQueue.front()));
|
||||
getBuf = chunk.data;
|
||||
chunksQueue.pop();
|
||||
curGetBufPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!getBuf.empty())
|
||||
return traits_type::to_int_type(getBuf[curGetBufPos]);
|
||||
else
|
||||
return traits_type::eof();
|
||||
}
|
||||
Reference in New Issue
Block a user