introduce emit_directives format option so consumers can implement append-only
All checks were successful
Generic zig build / build (push) Successful in 30s
All checks were successful
Generic zig build / build (push) Successful in 30s
This commit is contained in:
parent
ad894ff74a
commit
95036e83e2
1 changed files with 7 additions and 0 deletions
|
|
@ -658,6 +658,11 @@ pub const FormatOptions = struct {
|
||||||
|
|
||||||
/// Specify an expiration time for the data being written
|
/// Specify an expiration time for the data being written
|
||||||
expires: ?i64 = null,
|
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
|
/// Returns a formatter that formats the given value
|
||||||
|
|
@ -713,6 +718,7 @@ test fmt {
|
||||||
, formatted);
|
, formatted);
|
||||||
}
|
}
|
||||||
fn frontMatter(writer: *std.Io.Writer, options: FormatOptions) !void {
|
fn frontMatter(writer: *std.Io.Writer, options: FormatOptions) !void {
|
||||||
|
if (!options.emit_directives) return;
|
||||||
try writer.writeAll("#!srfv1\n");
|
try writer.writeAll("#!srfv1\n");
|
||||||
if (options.long_format)
|
if (options.long_format)
|
||||||
try writer.writeAll("#!long\n");
|
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});
|
try writer.print("#!expires={d}\n", .{e});
|
||||||
}
|
}
|
||||||
fn epilogue(writer: *std.Io.Writer, options: FormatOptions) !void {
|
fn epilogue(writer: *std.Io.Writer, options: FormatOptions) !void {
|
||||||
|
if (!options.emit_directives) return;
|
||||||
if (options.emit_eof)
|
if (options.emit_eof)
|
||||||
try writer.writeAll("#!eof\n");
|
try writer.writeAll("#!eof\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue