diff --git a/cmd/streamdata/main.go b/cmd/streamdata/main.go index c645f37..041a1cb 100644 --- a/cmd/streamdata/main.go +++ b/cmd/streamdata/main.go @@ -221,7 +221,7 @@ func main() { return errors.New("list requires a channel selected") } - for ident := range channel.All(&err) { + for ident := range channel.All(&err, true) { fmt.Println(ident) } return diff --git a/streamdata.go b/streamdata.go index b38971f..1c21477 100644 --- a/streamdata.go +++ b/streamdata.go @@ -276,7 +276,10 @@ func (c *Channel) Path(ident *Ident) string { // All returns an iterator over all known [Ident] in the on-disk representation. // Iteration stops when encountering the first non-nil error, and its value is // saved to the value pointed to by errP. -func (c *Channel) All(errP *error) iter.Seq[*Ident] { +// +// If reuse is true, the same value is updated every iteration and the same +// address is yileded as a result. +func (c *Channel) All(errP *error, reuse bool) iter.Seq[*Ident] { return func(yield func(*Ident) bool) { dents, err := c.root.FS().(fs.ReadDirFS).ReadDir(channelPathVOD) if err != nil { @@ -298,7 +301,11 @@ func (c *Channel) All(errP *error) iter.Seq[*Ident] { return } - if !yield(&ident) { + p := &ident + if !reuse { + p = new(ident) + } + if !yield(p) { return } } diff --git a/streamdata_test.go b/streamdata_test.go index 634ee2e..7d2cea9 100644 --- a/streamdata_test.go +++ b/streamdata_test.go @@ -303,7 +303,7 @@ func TestChannel(t *testing.T) { } var iterErr error - idents := slices.Collect(c.All(&iterErr)) + idents := slices.Collect(c.All(&iterErr, false)) if iterErr != nil { t.Fatalf("All: error = %#v", iterErr) }