/
Shymer123
/
Messenger
Обзор
Документация
Войти
/
Shymer123
/
Messenger
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
server
Server/SourceFiles/FileHandler/FileHandler.h
41 строка
1 KB
Shymer123
changed sending files to the client
25 мар 2025, 17:09
25 мар 2025, 17:09
b6b912b
Код
Авторство
О чём код?
#ifndef FILEHANDLER_H #define FILEHANDLER_H #include <cstdint> #include <nlohmann/json.hpp> #include <optional> #include <string> #include <fstream> class Server; struct FileTransferInfo { std::ofstream file; uint32_t totalChunks; uint32_t receivedChunks; }; class FileHandler { public: static std::optional<nlohmann::json> receiveFile(int clientSocket); static void sendFile(Server* server, int clientSocket, uint32_t fileID, const std::string& fileName); // file acceptance private: static std::optional<uint32_t> receiveFileCount(int clientSocket); static std::optional<nlohmann::json> receiveSingleFile(int clientSocket); static std::optional<uint32_t> receiveFileNameSize(int clientSocket); static std::optional<std::string> receiveFileName(int clientSocket, uint32_t nameSize); static std::optional<uint64_t> receiveFileSize(int clientSocket); static std::optional<uint32_t> receiveChunkCount(int clientSocket); static std::optional<nlohmann::json> saveFile(int clientSocket, const std::string& fileName, uint64_t fileSize, uint32_t chunkCount); static bool receiveAndWriteChunk(int clientSocket, std::ofstream& file, const std::string& fileName); static bool shouldDecompress(const std::string& fileName); }; #endif // FILEHANDLER_H