/
iterator.go
69 lines (53 loc) · 948 Bytes
/
iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ipfs
import (
"io/ioutil"
shell "github.com/ipfs/go-ipfs-api"
"github.com/syndtr/goleveldb/leveldb/iterator"
)
type Iterator struct {
it iterator.Iterator
rShell *shell.Shell
}
func (it *Iterator) Key() []byte {
return it.it.Key()
}
func (it *Iterator) Value1() []byte {
return it.it.Value()
}
func (it *Iterator) Value() []byte {
v := it.it.Value()
reader, err := it.rShell.Cat(string(v))
if err != nil {
return nil
}
data, err := ioutil.ReadAll(reader)
if err != nil {
return nil
}
return data
}
func (it *Iterator) Close() error {
if it.it != nil {
it.it.Release()
it.it = nil
}
return nil
}
func (it *Iterator) Valid() bool {
return it.it.Valid()
}
func (it *Iterator) Next() {
it.it.Next()
}
func (it *Iterator) Prev() {
it.it.Prev()
}
func (it *Iterator) First() {
it.it.First()
}
func (it *Iterator) Last() {
it.it.Last()
}
func (it *Iterator) Seek(key []byte) {
it.it.Seek(key)
}