Exemplo n.º 1
0
func (lfs localfileservice) PostBlob(b objects.Blob) (err error) {
	filepath := fmt.Sprintf("bin/blobs/%s", b.Hash().Hex())
	//log.Printf("[localfileservice] PostBlob %s", filepath)
	err = os.MkdirAll("bin/blobs", 0764)
	err = ioutil.WriteFile(filepath, b.Bytes(), 0664)
	return
}
Exemplo n.º 2
0
func (k kademliaservice) PostBlob(b objects.Blob) (err error) {
	values := url.Values{}
	values.Add("type", "blob")
	values.Add("hcid", b.Hash().Hex())
	_, err = k.postobject(values, b)
	if err != nil {
		log.Println(err)
		return err
	}
	//log.Printf("Responce: %s", data)
	return err
}
Exemplo n.º 3
0
func indexBlob(inBlob objects.Blob) {
	if blobIndex == nil {
		blobIndex = make(map[string]blobIndexEntry)
	}
	hashHex := inBlob.Hash().Hex()
	if _, present := blobIndex[hashHex]; !present {
		blobIndex[hashHex] = blobIndexEntry{HCID: hashHex}
	}
	blobIndex[hashHex] = blobIndex[hashHex].insertSize(len(inBlob))
	blobIndex[hashHex] = blobIndex[hashHex].insertType("Blob")

	indexText(inBlob)

}
Exemplo n.º 4
0
//type textIndexEntry struct {
//	blobToken string
//	blobHCID objects.HCID
//}
func indexText(inBlob objects.Blob) {
	if textIndex == nil {
		textIndex = make(map[string][]objects.HCID)
	}
	tokens := strings.FieldsFunc(string(inBlob), isSeperator)
	for _, token := range tokens {
		if _, present := textIndex[token]; !present {
			textIndex[token] = []objects.HCID{inBlob.Hash()}
		} else {
			textIndex[token] = append(
				textIndex[token],
				inBlob.Hash(),
			)
		}
	}
}