StoreData will store arbitrary data and return the corresponding hash
(data []byte)
| 501 | |
| 502 | // StoreData will store arbitrary data and return the corresponding hash |
| 503 | func (repo *GoGitRepo) StoreData(data []byte) (Hash, error) { |
| 504 | obj := repo.r.Storer.NewEncodedObject() |
| 505 | obj.SetType(plumbing.BlobObject) |
| 506 | |
| 507 | w, err := obj.Writer() |
| 508 | if err != nil { |
| 509 | return "", err |
| 510 | } |
| 511 | |
| 512 | _, err = w.Write(data) |
| 513 | if err != nil { |
| 514 | return "", err |
| 515 | } |
| 516 | |
| 517 | h, err := repo.r.Storer.SetEncodedObject(obj) |
| 518 | if err != nil { |
| 519 | return "", err |
| 520 | } |
| 521 | |
| 522 | return Hash(h.String()), nil |
| 523 | } |
| 524 | |
| 525 | // ReadData will attempt to read arbitrary data from the given hash |
| 526 | func (repo *GoGitRepo) ReadData(hash Hash) ([]byte, error) { |