本文整理匯總了Golang中restic/repository.Repository.LoadBlob方法的典型用法代碼示例。如果您正苦於以下問題:Golang Repository.LoadBlob方法的具體用法?Golang Repository.LoadBlob怎麽用?Golang Repository.LoadBlob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類restic/repository.Repository
的用法示例。
在下文中一共展示了Repository.LoadBlob方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: repackBlob
// repackBlob loads a single blob from src and saves it in dst.
func repackBlob(src, dst *repository.Repository, id backend.ID) error {
blob, err := src.Index().Lookup(id)
if err != nil {
return err
}
debug.Log("RepackBlobs", "repacking blob %v, len %v", id.Str(), blob.PlaintextLength())
buf := make([]byte, 0, blob.PlaintextLength())
buf, err = src.LoadBlob(blob.Type, id, buf)
if err != nil {
return err
}
if uint(len(buf)) != blob.PlaintextLength() {
debug.Log("RepackBlobs", "repack blob %v: len(buf) isn't equal to length: %v = %v", id.Str(), len(buf), blob.PlaintextLength())
return errors.New("LoadBlob returned wrong data, len() doesn't match")
}
_, err = dst.SaveAndEncrypt(blob.Type, buf, &id)
if err != nil {
return err
}
return nil
}
示例2: createFileAt
func (node Node) createFileAt(path string, repo *repository.Repository) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600)
defer f.Close()
if err != nil {
return errors.Annotate(err, "OpenFile")
}
var buf []byte
for _, id := range node.Content {
blob, err := repo.Index().Lookup(id)
if err != nil {
return err
}
buf = buf[:cap(buf)]
if uint(len(buf)) < blob.Length {
buf = make([]byte, blob.Length)
}
buf, err := repo.LoadBlob(pack.Data, id, buf)
if err != nil {
return errors.Annotate(err, "Load")
}
_, err = f.Write(buf)
if err != nil {
return errors.Annotate(err, "Write")
}
}
return nil
}
示例3: loadBlob
func loadBlob(t *testing.T, repo *repository.Repository, id backend.ID, buf []byte) []byte {
buf, err := repo.LoadBlob(pack.Data, id, buf)
if err != nil {
t.Fatalf("LoadBlob(%v) returned error %v", id, err)
}
return buf
}