-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluxshard.go
47 lines (42 loc) · 927 Bytes
/
fluxshard.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
package main
import (
"encoding/gob"
"encoding/json"
"io"
"os"
"path/filepath"
"strings"
"github.com/dfuse-io/doh/fluxdb"
"github.com/dfuse-io/dstore"
"github.com/spf13/cobra"
)
func viewFluxShard(cmd *cobra.Command, args []string) (err error) {
// Take the first param, use as filename, read as zstd
baseFile := filepath.Base(args[0])
storeURL := strings.TrimSuffix(args[0], baseFile)
store, err := dstore.NewStore(storeURL, "shard.zst", "zstd", false)
if err != nil {
return err
}
read, err := store.OpenObject(strings.TrimSuffix(baseFile, ".shard.zst"))
if err != nil {
return err
}
defer read.Close()
decoder := gob.NewDecoder(read)
encoder := json.NewEncoder(os.Stdout)
for {
req := new(fluxdb.WriteRequest)
err := decoder.Decode(&req)
if err == io.EOF {
break
}
if err != nil {
return err
}
if err := encoder.Encode(req); err != nil {
return err
}
}
return nil
}