feat: add Proof method to fetch bao file

This commit is contained in:
Derrick Hammer 2024-02-09 15:43:38 -05:00
parent 28d966cbe2
commit 850b575e1c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 28 additions and 0 deletions

View File

@ -179,3 +179,31 @@ func (f *FileImpl) Mime() string {
return record.MimeType return record.MimeType
} }
func (f *FileImpl) Protocol() string {
record, err := f.Record()
if err != nil {
return ""
}
return record.Protocol
}
func (f *FileImpl) Proof() ([]byte, error) {
object, err := f.renter.GetObject(context.Background(), f.Protocol(), f.HashString(), api.DownloadObjectOptions{})
if err != nil {
return nil, err
}
proof, err := io.ReadAll(object.Content)
if err != nil {
return nil, err
}
err = object.Content.Close()
if err != nil {
return nil, err
}
return proof, nil
}