[#791] neofs-lens: inspect objects by address

```
> neofs-lens list --path ./blob/blobovnicza/1/1/0
6ay4GfhR9RgN28d5ufg63toPetkYHGcpcW7G3b7QWSek/9ibXu6v4uTwLEcME5vyHev6Zi8LpxqiWTe1dahKpAbb6
H3VBttoLQoknzMDgnVNyLZ8EpkDnQjnaxDr9fnAWeEHA/Hw1titdGh7BrTe2yLotiYbVh9FQaRRNhoNzXTyetpFgt

> neofs-lens inspect --path ./blob/blobovnicza/1/1/0 \
    --address 6ay4GfhR9RgN28d5ufg63toPetkYHGcpcW7G3b7QWSek/9ibXu6v4uTwLEcME5vyHev6Zi8LpxqiWTe1dahKpAbb6 \
    --header --out payload
Version: v2.1
Type: REGULAR
CID: 6ay4GfhR9RgN28d5ufg63toPetkYHGcpcW7G3b7QWSek
ID: 9ibXu6v4uTwLEcME5vyHev6Zi8LpxqiWTe1dahKpAbb6
Owner: 2dokPzmmcLnnR21jQB3qPppTQRgwMNMKEWD
CreatedAt: 0
PayloadSize: 32
Attributes:
  foo: bar

> hexdump -C payload
00000000  ff 6c d4 71 c4 83 f1 5f  b9 0b ad b3 7c 58 21 b6  |.l.q..._....|X!.|
00000010  d9 55 26 a4 1a 95 04 68  0b 4e 7c 8b 76 3a 1b 1d  |.U&....h.N|.v:..|
00000020
```

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-10-13 14:23:03 +03:00 committed by Alex Vanin
parent e0f0188466
commit 1a1435be3d
3 changed files with 139 additions and 11 deletions

View file

@ -20,17 +20,8 @@ func (c *cache) Get(addr *objectSDK.Address) (*object.Object, error) {
}
c.mtx.RUnlock()
var value []byte
_ = c.db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(defaultBucket)
val := b.Get([]byte(saddr))
if val != nil {
value = cloneBytes(val)
}
return nil
})
if value != nil {
value, err := Get(c.db, []byte(saddr))
if err == nil {
obj := object.New()
c.flushed.Get(saddr)
return obj, obj.Unmarshal(value)
@ -66,3 +57,22 @@ func (c *cache) Head(addr *objectSDK.Address) (*object.Object, error) {
// NOTE: resetting the payload via the setter can lead to data corruption of in-memory objects, but ok for others
return object.NewRawFromObject(obj).CutPayload().Object(), nil
}
// Get fetches object from the underlying database.
// Key should be a stringified address.
func Get(db *bbolt.DB, key []byte) ([]byte, error) {
var value []byte
err := db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket(defaultBucket)
if b == nil {
return ErrNoDefaultBucket
}
value = b.Get(key)
if value == nil {
return object.ErrNotFound
}
value = cloneBytes(value)
return nil
})
return value, err
}