|
9 | 9 | "strings" |
10 | 10 |
|
11 | 11 | files "github.com/ipfs/boxo/files" |
12 | | - "github.com/ipfs/go-cid" |
13 | 12 | "github.com/ipfs/go-ipfs-api/options" |
14 | 13 | ) |
15 | 14 |
|
@@ -38,46 +37,6 @@ type DagImportOutput struct { |
38 | 37 | Stats *DagImportStats |
39 | 38 | } |
40 | 39 |
|
41 | | -type DagStat struct { |
42 | | - Cid cid.Cid `json:",omitempty"` |
43 | | - Size uint64 `json:",omitempty"` |
44 | | - NumBlocks int64 `json:",omitempty"` |
45 | | -} |
46 | | - |
47 | | -type DagStatOutput struct { |
48 | | - redundantSize uint64 `json:"-"` |
49 | | - UniqueBlocks int `json:",omitempty"` |
50 | | - TotalSize uint64 `json:",omitempty"` |
51 | | - SharedSize uint64 `json:",omitempty"` |
52 | | - Ratio float32 `json:",omitempty"` |
53 | | - DagStatsArray []*DagStat `json:"DagStats,omitempty"` |
54 | | -} |
55 | | - |
56 | | -func (s *DagStat) UnmarshalJSON(data []byte) error { |
57 | | - /* |
58 | | - We can't rely on cid.Cid.UnmarshalJSON since it uses the {"/": "..."} |
59 | | - format. To make the output consistent and follow the Kubo API patterns |
60 | | - we use the Cid.Parse method |
61 | | - */ |
62 | | - |
63 | | - type Alias DagStat |
64 | | - aux := struct { |
65 | | - Cid string `json:"Cid"` |
66 | | - *Alias |
67 | | - }{ |
68 | | - Alias: (*Alias)(s), |
69 | | - } |
70 | | - if err := json.Unmarshal(data, &aux); err != nil { |
71 | | - return err |
72 | | - } |
73 | | - Cid, err := cid.Parse(aux.Cid) |
74 | | - if err != nil { |
75 | | - return err |
76 | | - } |
77 | | - s.Cid = Cid |
78 | | - return nil |
79 | | -} |
80 | | - |
81 | 40 | func (s *Shell) DagGet(ref string, out interface{}) error { |
82 | 41 | return s.Request("dag/get", ref).Exec(context.Background(), out) |
83 | 42 | } |
@@ -192,45 +151,3 @@ func dagToFilesReader(data interface{}) (*files.MultiFileReader, error) { |
192 | 151 |
|
193 | 152 | return fileReader, nil |
194 | 153 | } |
195 | | - |
196 | | -// DagStat gets stats for dag with default options |
197 | | -func (s *Shell) DagStat(data string) (DagStatOutput, error) { |
198 | | - return s.DagStatWithOpts(data) |
199 | | -} |
200 | | - |
201 | | -// DagStatWithOpts gets stats for dag |
202 | | -func (s *Shell) DagStatWithOpts(data string, opts ...options.DagStatOption) (DagStatOutput, error) { |
203 | | - var out DagStatOutput |
204 | | - cfg, err := options.DagStatOptions(opts...) |
205 | | - if err != nil { |
206 | | - return out, err |
207 | | - } |
208 | | - |
209 | | - resp, err := s. |
210 | | - Request("dag/stat", data). |
211 | | - Option("progress", cfg.Progress). |
212 | | - Send(context.Background()) |
213 | | - |
214 | | - if err != nil { |
215 | | - return out, err |
216 | | - } |
217 | | - |
218 | | - defer resp.Close() |
219 | | - |
220 | | - if resp.Error != nil { |
221 | | - return out, resp.Error |
222 | | - } |
223 | | - |
224 | | - dec := json.NewDecoder(resp.Output) |
225 | | - for { |
226 | | - var v DagStatOutput |
227 | | - if err := dec.Decode(&v); err == io.EOF { |
228 | | - break |
229 | | - } else if err != nil { |
230 | | - return out, err |
231 | | - } |
232 | | - out = v |
233 | | - } |
234 | | - |
235 | | - return out, nil |
236 | | -} |
0 commit comments