Create a body from a file handle for streaming.
Creates a request body that streams data directly from a file handle, avoiding the need to load large files into memory. Supports three modes:
FILE *file = fopen("upload.dat", "rb");
if (file) {
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
fseek(file, 0, SEEK_SET);
"application/octet-stream", true, NULL, NULL);
}
typedef struct {
bool should_stop;
FILE *log_file;
} LogStreamContext;
LogStreamContext *ctx = (LogStreamContext*)userdata;
if (ctx->should_stop) {
}
long current_pos = ftell(ctx->log_file);
fseek(ctx->log_file, 0, SEEK_END);
long end_pos = ftell(ctx->log_file);
fseek(ctx->log_file, current_pos, SEEK_SET);
if (end_pos > current_pos) {
}
}
FILE *log_file = fopen("live.log", "rb");
LogStreamContext ctx = { .should_stop = false, .log_file = log_file };
continue_log_stream, &ctx);
fclose(log_file);
#ifdef _WIN32
HANDLE file = CreateFile(L"upload.dat", GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file != INVALID_HANDLE_VALUE) {
LARGE_INTEGER size;
GetFileSizeEx(file, &size);
"application/octet-stream", true,
NULL, NULL);
}
#endif
fetch_body_t * fetch_body_file(FETCH_FILE_HANDLE file_handle, size_t size, const char *content_type, bool close_on_free, fetch_file_continue_cb continue_cb, void *userdata)
Create a body from a file handle for streaming.
Definition fetch.c:8788
fetch_stream_result_t
Return codes for file streaming continue callback.
Definition fetch.h:73
@ FETCH_STREAM_DONE
Definition fetch.h:75
@ FETCH_STREAM_SKIP
Definition fetch.h:76
@ FETCH_STREAM_READ
Definition fetch.h:74