Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yyjson_read_fd and yyjson_write_fd #122

Closed
TkTech opened this issue May 10, 2023 · 2 comments
Closed

Add yyjson_read_fd and yyjson_write_fd #122

TkTech opened this issue May 10, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@TkTech
Copy link
Contributor

TkTech commented May 10, 2023

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.

@ibireme ibireme added the enhancement New feature or request label May 11, 2023
@ibireme
Copy link
Owner

ibireme commented May 11, 2023

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;
}

@ibireme
Copy link
Owner

ibireme commented May 14, 2023

Added: ac1191f

@ibireme ibireme closed this as completed May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants