// 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 }
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 }
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 }