summaryrefslogtreecommitdiff
path: root/cmd/btrfs-rec/util.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-01 22:43:58 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-01 22:43:58 -0700
commitd675f41242c043ddc4c6c1a1fb8aabcfd324aae2 (patch)
tree4f2afbce761eb377ad0b0ab2e4fb2f478ff844f5 /cmd/btrfs-rec/util.go
parent9971e38110d5f90d15c7b78f396f2638b3952a96 (diff)
parent6e1a9fbb1e9a943e04902ed3a4958f6821e39456 (diff)
Merge branch 'lukeshu/lint'
Diffstat (limited to 'cmd/btrfs-rec/util.go')
-rw-r--r--cmd/btrfs-rec/util.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/cmd/btrfs-rec/util.go b/cmd/btrfs-rec/util.go
index adfe97e..ffc03cc 100644
--- a/cmd/btrfs-rec/util.go
+++ b/cmd/btrfs-rec/util.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -34,7 +34,7 @@ func newRuneScanner(ctx context.Context, fh *os.File) (*runeScanner, error) {
progress: textui.Portion[int64]{
D: fi.Size(),
},
- progressWriter: textui.NewProgress[textui.Portion[int64]](ctx, dlog.LogLevelInfo, 1*time.Second),
+ progressWriter: textui.NewProgress[textui.Portion[int64]](ctx, dlog.LogLevelInfo, textui.Tunable(1*time.Second)),
reader: bufio.NewReader(fh),
closer: fh,
}
@@ -81,3 +81,14 @@ func readJSONFile[T any](ctx context.Context, filename string) (T, error) {
_ = buf.Close()
return ret, nil
}
+
+func writeJSONFile(w io.Writer, obj any, cfg lowmemjson.ReEncoder) (err error) {
+ buffer := bufio.NewWriter(w)
+ defer func() {
+ if _err := buffer.Flush(); err == nil && _err != nil {
+ err = _err
+ }
+ }()
+ cfg.Out = buffer
+ return lowmemjson.Encode(&cfg, obj)
+}