forked from sehejjain/DIS-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileutils.cpp
More file actions
39 lines (30 loc) · 793 Bytes
/
fileutils.cpp
File metadata and controls
39 lines (30 loc) · 793 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <algorithm>
#include "fileutils.h"
using namespace std;
size_t findSizeOfFile(FILE *fp)
{
fseek(fp, 0, SEEK_END);
size_t sz = ftell(fp);
fseek(fp, 0, SEEK_SET);
return sz;
}
size_t copy_into_buffer(FILE *fp, char **bufp, int index)
{
*bufp = (char *)malloc(pieceSize);
int position = index * pieceSize;
// fseek(fp, SEEK_SET, index*pieceSize+1);
size_t readsz = fread(*bufp, 1, pieceSize, fp);
return readsz;
}
void reconstruct_from_sections(vector<file_section> sections, int numberOfPieces)
{
FILE *fp = fopen("test.jpg", "wb");
for (int i = 0; i < numberOfPieces; i++)
{
fwrite(sections[i].databuf, 1, sections[i].size_of_databuf, fp);
}
}