func sendFileBlobs(c *blobserv.Client, part *multipart.Part) (respMeta map[string]interface{}) { meta := blob.NewMeta() defer func() { respMeta = map[string]interface{}{} respMeta["name"] = meta.Name respMeta["size"] = meta.Size if r := recover(); r != nil { respMeta["error"] = r.(error).Error() } }() obj := blob.NewObject() meta.RcasObjectRef = obj.Ref() meta.Name = part.FileName() data, err := ioutil.ReadAll(part) util.Check(err) meta.Size = int64(len(data)) blobs := blob.SplitRaw(data, blob.DefaultChunkSize) meta.ContentRefs = blob.RefsFor(blobs) m, err := blob.Marshal(meta) util.Check(err) blobs = append(blobs, m, obj) for _, b := range blobs { err = c.PutBlob(b) util.Check(err) } return respMeta }
func loadPicIndex() { nBlobs := 10 for skip := 0; true; skip += nBlobs { blobs, err := c.BlobsBackward(time.Now(), nBlobs, skip) if err != nil { break } for _, b := range blobs { if b.Type() == photos.IndexType { err := blob.Unmarshal(b, picIndex) util.Check(err) return } } if len(blobs) < nBlobs { break } } // no pre-existing photo index found picIndex = photos.NewIndex() obj := blob.NewObject() picIndex.RcasObjectRef = obj.Ref() err := c.PutBlob(obj) if err != nil { panic("pics: could not create photo index") } }
// Snap creates and sends an object-associated, updated snapshot of a file's // bytes to the blobserver. // // All meta-data associated with the file is left unchanged. func (m *Mount) Snap(path string) error { path = keyClean(path) var chunks []*blob.Blob newfm, err := m.getTip(path) if err == UntrackedErr { newfm = blob.NewMeta() obj := blob.NewObject() newfm.RcasObjectRef = obj.Ref() chunks, err = newfm.LoadFromPath(path) if err != nil { return err } mpath := filepath.Dir(filepath.Join(m.Prefix, m.keyPath(path))) newfm.SetNotes(Key, &Meta{Path: mpath}) chunks = append(chunks, obj) } else if err != nil { return err } chunks, err = newfm.LoadFromPath(path) if err != nil { return err } b, err := blob.Marshal(newfm) if err != nil { return err } chunks = append(chunks, b) m.Refs[path] = b.Ref() for _, b := range chunks { err := m.Client.PutBlob(b) if err != nil { return err } } return nil }
func testDir() { db, _ := blobdb.New(dbpath) metas, blobs, err := blob.DirBlobsAndMeta(testdirpath) if err != nil { fmt.Println(err) return } metablobs := make([]*blob.Blob, 0) for _, meta := range metas { obj := blob.NewObject() meta.RcasObjectRef = obj.Ref() m, _ := blob.Marshal(meta) metablobs = append(metablobs, m, obj) } err = db.Put(metablobs...) if err != nil { fmt.Println(err) return } err = db.Put(blobs...) if err != nil { fmt.Println(err) return } for _, b := range metablobs { fmt.Println(b) } for _, b := range blobs { fmt.Println(b) } }