BSON_READER_T(3)
π BSON_READER_T(3) π
okay so bestie, welcome to the libbson manual page for bson_reader_t β title BSON_READER_T(3), vibe streaming BSON documents, no cap. this one is short but iconic, fr fr. π
β¨ NAME β¨
Streaming BSON Document Reader π¦
πΈ SYNOPSIS πΈ
#include <bson/bson.h>
typedef struct _bson_reader_t bson_reader_t;
bson_reader_t *
bson_reader_new_from_handle (void *handle,
bson_reader_read_func_t rf,
bson_reader_destroy_func_t df);
bson_reader_t *
bson_reader_new_from_fd (int fd, bool close_on_destroy);
bson_reader_t *
bson_reader_new_from_file (const char *path, bson_error_t *error);
bson_reader_t *
bson_reader_new_from_data (const uint8_t *data, size_t length);
void
bson_reader_destroy (bson_reader_t *reader);
π DESCRIPTION π
So bson_reader_t is a structure used for reading a sequence of BSON documents. periodt. The sequence can come from a file-descriptor, memory region, or custom callbacks. it's giving flexible reader main character energy, fr fr. π
π¦ EXAMPLE π¦
Here's the example, bestie β it prints each BSON document contained in the provided files as a JSON string to STDOUT. the code is exactly what you need, so don't come for me about the long license block ππ
/*
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This program will print each BSON document contained in the provided files
* as a JSON string to STDOUT.
*/
#include <bson/bson.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
bson_reader_t *reader;
const bson_t *b;
bson_error_t error;
const char *filename;
char *str;
int i;
/*
* Print program usage if no arguments are provided.
*/
if (argc == 1) {
fprintf (stderr, "usage: %s [FILE | -]...\nUse - for STDIN.\n", argv[0]);
return 1;
}
/*
* Process command line arguments expecting each to be a filename.
*/
for (i = 1; i < argc; i++) {
filename = argv[i];
if (strcmp (filename, "-") == 0) {
reader = bson_reader_new_from_fd (STDIN_FILENO, false);
} else {
if (!(reader = bson_reader_new_from_file (filename, &error))) {
fprintf (
stderr, "Failed to open \"%s\": %s\n", filename, error.message);
continue;
}
}
/*
* Convert each incoming document to JSON and print to stdout.
*/
while ((b = bson_reader_read (reader, NULL))) {
str = bson_as_canonical_extended_json (b, NULL);
fprintf (stdout, "%s\n", str);
bson_free (str);
}
/*
* Cleanup after our reader, which closes the file descriptor.
*/
bson_reader_destroy (reader);
}
return 0;
}
π AUTHOR π
MongoDB, Inc π
π COPYRIGHT π
2009-present, MongoDB, Inc.
mwah π this little gem is from libbson version 2.5.6, dated Oct 09, 2026. now go stream those BSON docs, bestie β slay π«Άβ¨
π¦ where this page comes from
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms