-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.h
38 lines (28 loc) · 1008 Bytes
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include <memory>
#include <vector>
#include <string>
namespace ZipSync {
static const int SIZE_PATH = 4<<10;
static const int SIZE_FILEBUFFER = 64<<10;
static const int SIZE_LINEBUFFER = 16<<10;
template<class T> void AppendVector(std::vector<T> &dst, const std::vector<T> &src) {
dst.insert(dst.end(), src.begin(), src.end());
}
typedef std::unique_ptr<FILE, int (*)(FILE*)> StdioFileUniquePtr;
/**
* RAII wrapper around FILE* from stdio.h.
* Automatically closes file on destruction.
*/
class StdioFileHolder : public StdioFileUniquePtr {
public:
StdioFileHolder(FILE *f);
StdioFileHolder(const char *path, const char *mode); //checks that file is opened successfully
~StdioFileHolder();
StdioFileHolder(StdioFileHolder&&) = default;
StdioFileHolder& operator=(StdioFileHolder&&) = default;
operator FILE*() const { return get(); }
};
std::vector<uint8_t> ReadWholeFile(const std::string &filename);
int GetFileSize(const std::string &filename);
}