github.com/ethersphere/bee/v2@v2.2.0/pkg/file/addresses/addresses_getter.go (about) 1 // Copyright 2020 The Swarm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package addresses 6 7 import ( 8 "context" 9 10 storage "github.com/ethersphere/bee/v2/pkg/storage" 11 "github.com/ethersphere/bee/v2/pkg/swarm" 12 ) 13 14 type addressesGetterStore struct { 15 getter storage.Getter 16 fn swarm.AddressIterFunc 17 } 18 19 // NewGetter creates a new proxy storage.Getter which calls provided function 20 // for each chunk address processed. 21 func NewGetter(getter storage.Getter, fn swarm.AddressIterFunc) storage.Getter { 22 return &addressesGetterStore{getter, fn} 23 } 24 25 func (s *addressesGetterStore) Get(ctx context.Context, addr swarm.Address) (swarm.Chunk, error) { 26 ch, err := s.getter.Get(ctx, addr) 27 if err != nil { 28 return nil, err 29 } 30 31 return ch, s.fn(ch.Address()) 32 }