Exemple #1
0
func (db *Dbase) Get(ref string) (b *blob.Blob, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = errors.New(fmt.Sprint(r))
		}
	}()

	p := path.Join(db.location, ref)
	f, err := os.Open(p)
	if err != nil {
		return
	}
	defer f.Close()

	data, err := ioutil.ReadAll(f)
	if err != nil {
		return
	}

	hash, sum := blobRefParts(ref)
	b = blob.NewRaw(data)
	b.Hash = hash

	err = verifyBlob(sum, b)
	return b, nil
}
Exemple #2
0
func testQuery() {
	b1 := blob.NewRaw([]byte("I am not json"))
	b2 := blob.NewRaw([]byte("{\"key\":\"I am wrong json\"}"))
	b3 := blob.NewRaw([]byte("{\"key\":\"I am right json\"}"))

	q := query.New()

	isjson := q.NewFilter(query.IsJson)
	right := q.NewFilter(query.Contains("right"))

	isjson.SendTo(right)
	q.SetRoots(isjson)

	q.Open()
	defer q.Close()

	q.Process(b1, b2, b3)

	fmt.Println("results: ", q.Results)
}
Exemple #3
0
func (h *putHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	defer func() {
		if r := recover(); r != nil {
			w.Header().Set(ActionStatus, ActionFailed)
			fmt.Println("blob post issues: ", r)
		}
	}()

	body, err := ioutil.ReadAll(req.Body)
	util.Check(err)

	b := blob.NewRaw(body)
	err = h.bs.Db.Put(b)
	if err == blobdb.HashCollideErr {
		w.Header().Set(ActionStatus, ActionFailed)
		return
	}
	h.bs.notify(b)

	w.Header().Set(ActionStatus, ActionSuccess)
	fmt.Println("successful post")
}
Exemple #4
0
func testRaw() {
	db, err := blobdb.New(dbpath)
	if err != nil {
		fmt.Println(err)
		return
	}

	b := blob.NewRaw([]byte("hello monkey man"))
	err = db.Put(b)
	if err != nil {
		fmt.Println(err)
		return
	}

	b2, err := db.Get(b.Ref())
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(b)
	fmt.Println(b2)
}