This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -745,6 +745,38 @@ func (s *Shell) PubSubPublish(topic, data string) error {
745
745
return nil
746
746
}
747
747
748
+ type ObjectStats struct {
749
+ Hash string
750
+ BlockSize int
751
+ CumulativeSize int
752
+ DataSize int
753
+ LinksSize int
754
+ NumLinks int
755
+ }
756
+
757
+ // ObjectStat gets stats for the DAG object named by key. It returns
758
+ // the stats of the requested Object or an error.
759
+ func (s * Shell ) ObjectStat (key string ) (* ObjectStats , error ) {
760
+ resp , err := s .newRequest ("object/stat" , key ).Send (s .httpcli )
761
+ if err != nil {
762
+ return nil , err
763
+ }
764
+ defer resp .Close ()
765
+
766
+ if resp .Error != nil {
767
+ return nil , resp .Error
768
+ }
769
+
770
+ stat := & ObjectStats {}
771
+
772
+ err = json .NewDecoder (resp .Output ).Decode (stat )
773
+ if err != nil {
774
+ return nil , err
775
+ }
776
+
777
+ return stat , nil
778
+ }
779
+
748
780
func (s * Shell ) DiagNet (format string ) ([]byte , error ) {
749
781
var result = new (bytes.Buffer )
750
782
Original file line number Diff line number Diff line change @@ -201,3 +201,14 @@ func TestPubSub(t *testing.T) {
201
201
202
202
is .Nil (sub .Cancel ())
203
203
}
204
+
205
+ func TestObjectStat (t * testing.T ) {
206
+ obj := "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
207
+ is := is .New (t )
208
+ s := NewShell (shellUrl )
209
+ stat , err := s .ObjectStat ("QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V" )
210
+ is .Nil (err )
211
+ is .Equal (stat .Hash , obj )
212
+ is .Equal (stat .LinksSize , 3 )
213
+ is .Equal (stat .CumulativeSize , 1688 )
214
+ }
You can’t perform that action at this time.
0 commit comments