Closed TkTech closed 1 year ago
I think yyjson_read_fp(FILE *fp, ...) might be better because FILE
is ANSI C and file descriptor
is platform-dependent.
The caller could use it like this:
// POSIX
yyjson_doc *read_fd(int fd) {
FILE *fp = fdopen(fd, "r")
yyjson_doc *doc = yyjson_read_fp(fd);
fclose(fp);
return doc;
}
There are many scenarios where I have access to a file descriptor (or HANDLE on win32) but not a path. For example, a secure temporary file on Linux can be just a floating inode - it doesn't actually have a file path at all.
This would make supporting high-level wrappers such as Python simpler, since just the file handle can be pushed down to yyjson from any file-like object that supports it. We don't want to read the file handle in Python and then pass the data to yyjson, as this requires a double allocation.