Skip to content

Commit

Permalink
add data_cb comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Sep 20, 2023
1 parent bea2835 commit ca8b923
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Install deps
run: |
sudo apt update && sudo apt install -y valgrind libcurl4-openssl-dev
- name: Run tests
run: |
make test
- name: Run examples
run: |
make run-examples
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
run-examples:
zig build run-basic -freference-trace
zig build run-advanced -freference-trace

test:
zig build test

.PHONY: test run-examples
12 changes: 5 additions & 7 deletions examples/advanced.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn put_with_custom_header(allocator: Allocator, easy: Easy) !void {
const resp = try easy.do(req);
defer resp.deinit();

std.debug.print("Status code: {d}\nBody: [{s}]\n", .{
std.debug.print("Status code: {d}\nBody: {s}\n", .{
resp.status_code,
resp.body.items,
});
Expand Down Expand Up @@ -82,12 +82,10 @@ fn put_with_custom_header(allocator: Allocator, easy: Easy) !void {
}
}

fn post_mutli_part(allocator: Allocator, easy: Easy) !void {
_ = allocator;

fn post_mutli_part(easy: Easy) !void {
const multi_part = try easy.add_multi_part();
try multi_part.add_part("foo", .{ .memory = "hello foo" });
try multi_part.add_part("bar", .{ .memory = "hello bar" });
try multi_part.add_part("foo", .{ .data = "hello foo" });
try multi_part.add_part("bar", .{ .data = "hello bar" });
try multi_part.add_part("build.zig", .{ .file = "build.zig" });
try multi_part.add_part("readme", .{ .file = "README.org" });

Expand Down Expand Up @@ -116,5 +114,5 @@ pub fn main() !void {

println("PUT with custom header demo");
try put_with_custom_header(allocator, easy);
try post_mutli_part(allocator, easy);
try post_mutli_part(easy);
}
11 changes: 8 additions & 3 deletions src/easy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ pub const MultiPart = struct {
allocator: Allocator,

pub const DataSource = union(enum) {
memory: []const u8,
/// Set a mime part's body content from memory data.
/// Data will get copied when send request.
/// Setting large data is memory consuming: one might consider using `data_callback` in such a case.
data: []const u8,
/// Set a mime part's body data from a file contents.
file: []const u8,
// read_callback :
// TODO: https://curl.se/libcurl/c/curl_mime_data_cb.html
// data_callback: u8,
};

pub fn deinit(self: @This()) void {
Expand All @@ -204,7 +209,7 @@ pub const MultiPart = struct {

try checkCode(c.curl_mime_name(part, namez));
switch (source) {
.memory => |slice| {
.data => |slice| {
try checkCode(c.curl_mime_data(part, slice.ptr, slice.len));
},
.file => |filepath| {
Expand Down

0 comments on commit ca8b923

Please sign in to comment.