atproto pds in zig pds.zat.dev
pds atproto
24

Configure Feed

Select the types of activity you want to include in your feed.

Persist blobs without Io writeFile

zzstoatzz (May 22, 2026, 4:20 PM -0500) b6857196 31476fc6

+30 -5
+30 -5
src/storage/blobstore.zig
··· 12 12 } 13 13 14 14 pub fn put(allocator: std.mem.Allocator, io: Io, did: []const u8, cid: []const u8, data: []const u8) !void { 15 + _ = io; 15 16 try requireInitialized(); 16 17 const dir_path = try actorDirPath(allocator, did); 17 - try Io.Dir.cwd().createDirPath(io, dir_path); 18 + try mkdirPath(allocator, dir_path); 18 19 const path = try blobPath(allocator, did, cid); 19 - try Io.Dir.cwd().writeFile(io, .{ 20 - .sub_path = path, 21 - .data = data, 22 - }); 20 + try writeFileC(allocator, path, data); 23 21 } 24 22 25 23 pub fn get(allocator: std.mem.Allocator, did: []const u8, cid: []const u8, limit: usize) ![]u8 { ··· 48 46 fn trimTrailingSlash(value: []const u8) []const u8 { 49 47 if (value.len > 1 and value[value.len - 1] == '/') return value[0 .. value.len - 1]; 50 48 return value; 49 + } 50 + 51 + fn mkdirPath(allocator: std.mem.Allocator, path: []const u8) !void { 52 + var index: usize = 0; 53 + while (index < path.len) : (index += 1) { 54 + if (path[index] != std.fs.path.sep) continue; 55 + if (index == 0) continue; 56 + try mkdirOne(allocator, path[0..index]); 57 + } 58 + try mkdirOne(allocator, path); 59 + } 60 + 61 + fn mkdirOne(allocator: std.mem.Allocator, path: []const u8) !void { 62 + const path_z = try allocator.dupeZ(u8, path); 63 + if (std.c.mkdir(path_z.ptr, 0o755) == 0) return; 64 + const err: std.posix.E = @enumFromInt(std.posix.system._errno().*); 65 + if (err == .EXIST) return; 66 + return error.CreateDirFailed; 67 + } 68 + 69 + fn writeFileC(allocator: std.mem.Allocator, path: []const u8, data: []const u8) !void { 70 + const path_z = try allocator.dupeZ(u8, path); 71 + const file = std.c.fopen(path_z.ptr, "wb") orelse return error.OpenBlobFailed; 72 + defer _ = std.c.fclose(file); 73 + if (data.len == 0) return; 74 + const written = std.c.fwrite(data.ptr, 1, data.len, file); 75 + if (written != data.len) return error.WriteBlobFailed; 51 76 } 52 77 53 78 test "disk blobstore writes and reads account blob bytes" {