From 95036e83e26bb885641c62aaf1e26dbfbb147ea9 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 6 Mar 2026 17:30:07 -0800 Subject: [PATCH] introduce emit_directives format option so consumers can implement append-only --- src/srf.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/srf.zig b/src/srf.zig index 0a66f64..9b6aea8 100644 --- a/src/srf.zig +++ b/src/srf.zig @@ -658,6 +658,11 @@ pub const FormatOptions = struct { /// Specify an expiration time for the data being written expires: ?i64 = null, + + /// By setting this to false, you can avoid writing any header/footer data + /// and just format the record. This is useful for appending to an existing + /// srf file rather than overwriting all the data + emit_directives: bool = true, }; /// Returns a formatter that formats the given value @@ -713,6 +718,7 @@ test fmt { , formatted); } fn frontMatter(writer: *std.Io.Writer, options: FormatOptions) !void { + if (!options.emit_directives) return; try writer.writeAll("#!srfv1\n"); if (options.long_format) try writer.writeAll("#!long\n"); @@ -722,6 +728,7 @@ fn frontMatter(writer: *std.Io.Writer, options: FormatOptions) !void { try writer.print("#!expires={d}\n", .{e}); } fn epilogue(writer: *std.Io.Writer, options: FormatOptions) !void { + if (!options.emit_directives) return; if (options.emit_eof) try writer.writeAll("#!eof\n"); }