Removed compiler warnings, starting to import large files
This commit is contained in:
parent
9ec06749f2
commit
bf0cbfb412
21 changed files with 143 additions and 82 deletions
|
@ -4,24 +4,35 @@
|
|||
|
||||
#define MAX_DATA_SIZE 262144 // 1024 * 256;
|
||||
|
||||
/***
|
||||
* Imports OS files into the datastore
|
||||
*/
|
||||
|
||||
/**
|
||||
* read the next chunk of bytes, create a node, and add a link to the node in the passed-in node
|
||||
* @param file the file handle
|
||||
* @param node the node to add to
|
||||
* @returns number of bytes read
|
||||
*/
|
||||
int ipfs_import_chunk(FILE* file, struct Node* node) {
|
||||
size_t ipfs_import_chunk(FILE* file, struct Node* node) {
|
||||
unsigned char buffer[MAX_DATA_SIZE];
|
||||
size_t bytes_read = fread(buffer, MAX_DATA_SIZE, 1, file);
|
||||
if (node->data_size == 0) {
|
||||
Node_Set_Data(node, buffer, bytes_read);
|
||||
ipfs_node_set_data(node, buffer, bytes_read);
|
||||
if (bytes_read != MAX_DATA_SIZE) {
|
||||
// persist
|
||||
}
|
||||
} else {
|
||||
// create a new node, and link to the parent
|
||||
struct Node* new_node = N_Create_From_Data(buffer, bytes_read);
|
||||
struct Node* new_node = NULL;
|
||||
ipfs_node_new_from_data(buffer, bytes_read, &new_node);
|
||||
// persist
|
||||
|
||||
// put link in node
|
||||
Node_Add_Link(node, Create_Link("", new_node->cached->hash));
|
||||
Node_Delete(new_node);
|
||||
struct NodeLink* new_link = NULL;
|
||||
ipfs_node_link_new("", new_node->cached->hash, &new_link);
|
||||
ipfs_node_add_link(node, new_link);
|
||||
ipfs_node_free(new_node);
|
||||
}
|
||||
return bytes_read;
|
||||
}
|
||||
|
@ -34,12 +45,17 @@ int ipfs_import_chunk(FILE* file, struct Node* node) {
|
|||
*/
|
||||
int ipfs_import_file(const char* fileName, struct Node** node) {
|
||||
int retVal = 1;
|
||||
int bytes_read = MAX_DATA_SIZE;
|
||||
|
||||
FILE* file = fopen(fileName, "rb");
|
||||
*node = (struct Node)malloc(sizeof(struct Node));
|
||||
retVal = ipfs_node_new(node);
|
||||
if (retVal == 0)
|
||||
return 0;
|
||||
|
||||
// add all nodes
|
||||
while (ipfs_import_chunk(file, *node) == MAX_DATA_SIZE) {}
|
||||
while ( bytes_read == MAX_DATA_SIZE) {
|
||||
bytes_read = ipfs_import_chunk(file, *node);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue