Skip to content

Commit

Permalink
tech feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
norareidy committed Oct 11, 2024
1 parent 667ab67 commit 3c00d27
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions source/includes/write/gridfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ main (void)
// Creates a GridFS bucket and specifies a custom name
// start-create-custom-bucket
mongoc_database_t *db = mongoc_client_get_database (client, "db");
bson_t opts;
bson_init(&opts);
bson_t opts = BSON_INITIALIZER;
BSON_APPEND_UTF8 (&opts, "bucketName", "myCustomBucket");

bson_error_t error;
Expand All @@ -43,10 +42,11 @@ main (void)
bson_error_t error;
mongoc_stream_t *upload_stream = mongoc_gridfs_bucket_open_upload_stream (bucket, "my_file", NULL, NULL, &error);
if (upload_stream == NULL) {
fprintf (stderr, "Failed to create upload stream: %s\n", error.message);
fprintf (stderr, "Failed to create upload stream: %s\n", error.message);
} else {
const char *data = "Data to store";
mongoc_stream_write (upload_stream, data, strlen(data), -1);
}
const char *data = "Data to store";
mongoc_stream_write (upload_stream, data, strlen(data), -1);

mongoc_stream_close (upload_stream);
mongoc_stream_destroy (upload_stream);
Expand Down Expand Up @@ -88,11 +88,9 @@ main (void)
// Creates a download stream for a given file ID
// start-open-download-stream
char buf[512];
bson_oid_t oid;
bson_oid_init_from_string (&oid, "66fb1b8ea0f84a74ee099e71");
bson_value_t file_id;
file_id.value_type = BSON_TYPE_OID;
memcpy(&file_id.value.v_oid, &oid, sizeof(bson_oid_t));
file_id.value_type = BSON_TYPE_OID;
bson_oid_init_from_string (&file_id.value.v_oid, "66fb1b8ea0f84a74ee099e71");

bson_error_t error;
mongoc_stream_t *download_stream = mongoc_gridfs_bucket_open_download_stream (bucket, &file_id, &error);
Expand All @@ -115,11 +113,9 @@ main (void)
fprintf (stderr, "Error opening file stream: %s\n", error.message);
}

bson_oid_t oid;
bson_oid_init_from_string (&oid, "66fb1b8ea0f84a74ee099e71");
bson_value_t file_id;
file_id.value_type = BSON_TYPE_OID;
memcpy(&file_id.value.v_oid, &oid, sizeof(bson_oid_t));
file_id.value_type = BSON_TYPE_OID;
bson_oid_init_from_string (&file_id.value.v_oid, "66fb1b8ea0f84a74ee099e71");

if (!mongoc_gridfs_bucket_download_to_stream (bucket, &file_id, file_stream, &error)) {
fprintf (stderr, "Failed to download file: %s\n", error.message);
Expand Down

0 comments on commit 3c00d27

Please sign in to comment.