introduce emit_directives format option so consumers can implement append-only
All checks were successful
Generic zig build / build (push) Successful in 30s

This commit is contained in:
Emil Lerch 2026-03-06 17:30:07 -08:00
parent ad894ff74a
commit 95036e83e2
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -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");
}