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 @@ -710,6 +710,38 @@ func (s *Shell) PubSubPublish(topic, data string) error {
710710 return nil
711711}
712712
713+ type ObjectStats struct {
714+ Hash string
715+ BlockSize int
716+ CumulativeSize int
717+ DataSize int
718+ LinksSize int
719+ NumLinks int
720+ }
721+
722+ // ObjectStat gets stats for the DAG object named by key. It returns
723+ // the stats of the requested Object or an error.
724+ func (s * Shell ) ObjectStat (key string ) (* ObjectStats , error ) {
725+ resp , err := s .newRequest ("object/stat" , key ).Send (s .httpcli )
726+ if err != nil {
727+ return nil , err
728+ }
729+ defer resp .Close ()
730+
731+ if resp .Error != nil {
732+ return nil , resp .Error
733+ }
734+
735+ stat := & ObjectStats {}
736+
737+ err = json .NewDecoder (resp .Output ).Decode (stat )
738+ if err != nil {
739+ return nil , err
740+ }
741+
742+ return stat , nil
743+ }
744+
713745func (s * Shell ) DiagNet (format string ) ([]byte , error ) {
714746 var result = new (bytes.Buffer )
715747
Original file line number Diff line number Diff line change @@ -167,3 +167,14 @@ func TestPubSub(t *testing.T) {
167167
168168 is .Nil (sub .Cancel ())
169169}
170+
171+ func TestObjectStat (t * testing.T ) {
172+ obj := "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"
173+ is := is .New (t )
174+ s := NewShell (shellUrl )
175+ stat , err := s .ObjectStat ("QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V" )
176+ is .Nil (err )
177+ is .Equal (stat .Hash , obj )
178+ is .Equal (stat .LinksSize , 3 )
179+ is .Equal (stat .CumulativeSize , 1688 )
180+ }
You can’t perform that action at this time.
0 commit comments