Added first cut of get_object

This commit is contained in:
jmjatlanta 2017-09-20 07:02:00 -05:00
parent 64891c9198
commit 6db0830c7d

View file

@ -276,8 +276,44 @@ size_t boundary_size(char *str, char *boundary, size_t limit)
*/ */
int get_object(char *path, unsigned char **obj, size_t *size) int get_object(char *path, unsigned char **obj, size_t *size)
{ {
// TODO: implement. FILE* memstream_file = NULL;
return 0; // fail. char* memstream_char = NULL;
size_t memstream_size = 0;
struct Cid* cid = NULL;
// convert hash to cid
if ( ipfs_cid_decode_hash_from_base58((unsigned char*)path, strlen(path), &cid) == 0) {
return 0;
}
// find block
struct HashtableNode* read_node = NULL;
if (!ipfs_exporter_get_node(local_node, cid->hash, cid->hash_length, &read_node)) {
ipfs_cid_free(cid);
return 0;
}
// open a memory stream
memstream_file = open_memstream(&memstream_char, &memstream_size);
if (memstream_file == NULL) {
libp2p_logger_error("api", "get_object: Unable to open a memory stream.\n");
ipfs_cid_free(cid);
return 0;
}
// throw everything (including links) into the memory stream
ifps_exporter_cat_node(read_node, local_node, memstream_file);
fclose(memstream_file);
// no longer need these
ipfs_cid_free(cid);
libp2p_hashtable_node_free(read_node);
*size = memstream_size;
*obj = memstream_char;
return 1;
} }
/** /**