本文整理汇总了Golang中github.com/AaronGoldman/ccfs/objects.Blob函数的典型用法代码示例。如果您正苦于以下问题:Golang Blob函数的具体用法?Golang Blob怎么用?Golang Blob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Blob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMulticastservice_GetBlob
func TestMulticastservice_GetBlob(t *testing.T) {
//t.Skipf("Come back to this test")
web.Start()
//go BlobServerStart()
AnswerKey := []struct {
hcid objects.HCID
response objects.Blob
}{
{objects.Blob([]byte("blob found")).Hash(), objects.Blob([]byte("blob found"))},
}
for _, answer := range AnswerKey {
localfile.Instance.PostBlob(answer.response)
go func() {
time.Sleep(1 * time.Millisecond)
mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:1234")
Instance.receivemessage("{\"type\":\"blob\", \"hcid\": \"42cc3a4c4a9d9d3ee7de9322b45acb0e5a5c33550d9ad4791df6ae937a869e12\", \"URL\": \"/b/42cc3a4c4a9d9d3ee7de9322b45acb0e5a5c33550d9ad4791df6ae937a869e12\"}", mcaddr)
}()
output, err := Instance.GetBlob(answer.hcid)
if err != nil {
t.Errorf("Get Blob Failed \nError:%s", err)
} else if !bytes.Equal(output.Hash(), answer.hcid) {
t.Errorf("Get Blob Failed \nExpected:%s \nGot: %s", answer.response, output)
}
}
}
示例2: TestPostTagTagBlob
func TestPostTagTagBlob(t *testing.T) {
testhkid := objects.HkidFromDString("46298148238932964800164113348087"+
"9383618612455972320097996217675372497646408870646300138355611242"+
"4820911870650421151988906751710824965155500230480521264034469", 10)
domain1Hkid := objects.HkidFromDString("32076859881811206392323279987831"+
"3732334949433938278619036381396945204532895319697233476900342324"+
"1692155627674142765782672165943417419038514237233188152538761", 10)
domain2Hkid := objects.HkidFromDString("49220288257701056900010210884990"+
"0714973444364727181180850528073586453638681999434006549298762097"+
"4197649255374796716934112121800838847071661501215957753532505", 10)
err := services.InsertDomain(testhkid, "testTag1", domain1Hkid)
if err != nil {
t.Errorf("InsertDomain with error: %s", err)
}
err = services.InsertDomain(testhkid, "testTag1/testTag2", domain2Hkid)
if err != nil {
t.Errorf("InsertDomain with error: %s", err)
}
indata := objects.Blob([]byte("TestTagTagBlobData"))
testpath := "testTag1/testTag2/testBlob"
_, err = services.Post(testhkid, testpath, indata)
outdata, err := services.Get(testhkid, testpath)
if err != nil {
log.Printf("[TestPostTagTagBlob] testhkid %s", testhkid)
log.Printf("[TestPostTagTagBlob] domain1Hkid %s", domain1Hkid)
log.Printf("[TestPostTagTagBlob] domain2Hkid %s", domain2Hkid)
t.Errorf("Retreved with error: %s", err)
} else if !bytes.Equal(indata, outdata) {
t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata)
}
}
示例3: TestMulticastservice_GetTag
func TestMulticastservice_GetTag(t *testing.T) {
//t.Skipf("Come back to this test")
//log.Printf("The key generated is, %d", KeyGen().D)
//hkid := HKID{}
hkid := objects.HkidFromDString("6450698573071574057685373503239926609554390924514830851922442833127942726436428023022500281659846836919706975681006884631876585143520956760217923400876937896", 10)
b := objects.Blob([]byte("blob found"))
tagT := objects.NewTag(b.Hash(), "blob", "BlobinTag", hkid)
localfile.Instance.PostTag(tagT)
go func() {
time.Sleep(1 * time.Millisecond)
mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8000")
Instance.receivemessage(fmt.Sprintf("{\"type\":\"tag\", \"hkid\": \"%s\", \"namesegment\": \"%s\", \"URL\": \"/t/%s/%s/%d\"}", hkid, tagT.NameSegment, hkid, tagT.NameSegment, tagT.Version), mcaddr)
}()
output, err := Instance.GetTag(tagT.Hkid(), tagT.NameSegment)
if err != nil {
t.Errorf("Get Tag Failed \nError:%s", err)
} else if !output.Verify() {
//!bytes.Equal(output.Hash(), tag_t.Hash()) {
t.Errorf("Get Tag Failed \nExpected:%s \nGot: %s", tagT, output)
}
if output.Version != tagT.Version {
log.Printf("Tag is stale %d", tagT.Version-output.Version)
}
}
示例4: TestMulticastservice_GetCommit
func TestMulticastservice_GetCommit(t *testing.T) {
//t.Skipf("Come back to this test")
hkid := objects.HkidFromDString("5198719439877464148627795433286736285873678110640040333794349799294848737858561643942881983506066042818105864129178593001327423646717446545633525002218361750", 10)
b := objects.Blob([]byte("blob found"))
l := objects.NewList(b.Hash(), "blob", "Blobinlist")
c := objects.NewCommit(l.Hash(), hkid)
localfile.Instance.PostCommit(c)
go func() {
time.Sleep(1 * time.Millisecond)
mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8000")
Instance.receivemessage(fmt.Sprintf("{\"type\":\"commit\", \"hkid\": \"9bd1b3c9aeda7025068319c0a4af1d2b7b644066c9820d247b19f1b9bf40840c\", \"URL\": \"/c/9bd1b3c9aeda7025068319c0a4af1d2b7b644066c9820d247b19f1b9bf40840c/%d\"}", c.Version), mcaddr)
}()
output, err := Instance.GetCommit(c.Hkid())
if err != nil {
t.Errorf("Get Commit Failed \nError:%s", err)
} else if !output.Verify() {
//else if !bytes.Equal(output.Hash(), c.Hash()) {
t.Errorf("Get Commit Failed \nExpected:%s \nGot: %s", c, output)
}
if output.Version() != c.Version() {
log.Printf("Commit is stale %d", c.Version()-output.Version())
}
}
示例5: PostCommit
func (lfs localfileservice) PostCommit(c objects.Commit) (err error) {
lfs.PostBlob(objects.Blob(c.Bytes()))
filepath := fmt.Sprintf("bin/commits/%s/%d", c.Hkid.Hex(), c.Version)
//log.Printf("[localfileservice] PostCommit %s\n\t%d", filepath, c.Version())
dirpath := fmt.Sprintf("bin/commits/%s", c.Hkid.Hex())
err = os.MkdirAll(dirpath, 0764)
err = ioutil.WriteFile(filepath, c.Bytes(), 0664)
return
}
示例6: postBlob
func postBlob(data string) objects.HCID {
testBlob := objects.Blob([]byte(data)) //gen test blob
err := services.PostBlob(testBlob) //store test blob
if err != nil {
log.Println(err)
}
return testBlob.Hash()
}
示例7: TestLowLevel
func TestLowLevel(t *testing.T) {
indata := objects.Blob([]byte("TestPostData"))
services.PostBlob(indata)
blobhcid, err := objects.HcidFromHex(
"ca4c4244cee2bd8b8a35feddcd0ba36d775d68637b7f0b4d2558728d0752a2a2",
)
b, err := services.GetBlob(blobhcid)
if !bytes.Equal(b.Hash(), blobhcid) {
t.Fatalf("GetBlob Fail\nExpected: %s\nGot: %s\n", blobhcid, b.Hash()) //Changed
}
//6dedf7e580671bd90bc9d1f735c75a4f3692b697f8979a147e8edd64fab56e85
testhkid := objects.HkidFromDString(
"6523237356270560228617783789728329416595512649112249373497830592"+
"0722414168936112160694238047304378604753005642729767620850685191"+
"88612732562106886379081213385", 10)
testCommit := objects.NewCommit(b.Hash(), testhkid)
services.PostCommit(testCommit)
c, err := services.GetCommit(testhkid)
if err != nil {
t.Fatalf("Get Commit Fail: %s", err)
} else if !bytes.Equal(c.Hkid, testhkid) {
t.Fatalf("Expected: %s Got: %s", testhkid, c.Hkid)
} else if !c.Verify() {
t.Fatalf("Commit Signature Invalid.")
}
//ede7bec713c93929751f18b1db46d4be3c95286bd5f2d92b9759ff02115dc312
taghkid := objects.HkidFromDString(
"4813315537186321970719165779488475377688633084782731170482174374"+
"7256947679650787426167575073363006751150073195493002048627629373"+
"76227751462258339344895829332", 10)
lowlvlTag := objects.NewTag(
objects.HID(b.Hash()),
"blob",
"testBlob",
nil,
taghkid,
) //gen test tag
services.PostTag(lowlvlTag)
testtag, err := services.GetTag(taghkid, lowlvlTag.NameSegment)
if err != nil {
t.Fatalf("GetTag Fail. error: %s", err)
} else if !bytes.Equal(testtag.Hkid, taghkid) {
t.Fatalf("GetTag Fail.\n\t expected: %v\n\t got: %v", taghkid, testtag.Hkid)
} else if !testtag.Verify() {
t.Fatalf("GetTag Verify Fail")
}
prikey, err := services.GetKey(taghkid)
if err != nil || !bytes.Equal(prikey.Hkid(), taghkid) || !prikey.Verify() {
t.Logf("GetKey Fail")
t.Fail()
}
}
示例8: PostTag
func (lfs localfileservice) PostTag(t objects.Tag) (err error) {
lfs.PostBlob(objects.Blob(t.Bytes()))
filepath := fmt.Sprintf("bin/tags/%s/%s/%d", t.Hkid.Hex(),
t.NameSegment, t.Version)
//log.Printf("[localfileservice] PostTag %s", filepath)
dirpath := fmt.Sprintf("bin/tags/%s/%s", t.Hkid.Hex(),
t.NameSegment)
err = os.MkdirAll(dirpath, 0764)
err = ioutil.WriteFile(filepath, t.Bytes(), 0664)
return
}
示例9: BenchmarkListBlobFound
func BenchmarkListBlobFound(b *testing.B) {
indata := objects.Blob("List Blob Found Data")
services.Post(benchmarkRepo, "listFound/BlobFound", indata)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := services.Get(benchmarkRepo, "listFound/BlobFound")
if err != nil {
b.Fatalf("Failed to find List Blob: %s", err)
}
}
}
示例10: TestPostListListBlob
func TestPostListListBlob(t *testing.T) {
testhkid := objects.HkidFromDString("65232373562705602286177837897283294165955126"+
"49112249373497830592072241416893611216069423804730437860475300564272"+
"976762085068519188612732562106886379081213385", 10)
testpath := "TestPostList1/TestPostList2/TestPostBlob"
indata := []byte("TestPostListListBlobData")
services.Post(testhkid, testpath, objects.Blob(indata))
outdata, err := services.Get(testhkid, testpath)
if !bytes.Equal(indata, outdata) || err != nil {
t.Fail()
}
}
示例11: TestKademliaserviceBlob
func TestKademliaserviceBlob(t *testing.T) {
indata := objects.Blob("TestPostData")
Instance.PostBlob(indata)
outdata, err := Instance.GetBlob(indata.Hash())
if err != nil {
t.Errorf("\nErr:%s", err)
}
if !bytes.Equal(indata, outdata) {
t.Errorf("\nExpected:%s\nGot:%s", indata, outdata)
}
}
示例12: BenchmarkListBlobUpdate
func BenchmarkListBlobUpdate(b *testing.B) {
indata := objects.Blob("Benchmark Blob Data")
services.Post(benchmarkRepo, "listFound/benchmarkBlob", indata)
b.ResetTimer()
for i := 0; i < b.N; i++ {
services.Post(benchmarkRepo, "listFound/benchmarkBlob", indata)
}
outdata, err := services.Get(benchmarkRepo, "listFound/benchmarkBlob")
if !bytes.Equal(indata, outdata) || err != nil {
b.Fatalf("\tExpected: %s\n\tActual: %s\n\tErr:%s\n",
indata, outdata, err)
}
}
示例13: BenchmarkBlobInsert
//BenchmarkBlobInsert times the posting of a blob to a repository.
func BenchmarkBlobInsert(b *testing.B) {
indata := objects.Blob("Benchmark Blob Data")
b.ResetTimer()
for i := 0; i < b.N; i++ {
services.Post(benchmarkRepo, "benchmarkBlob", indata)
//TODO clear blob after each insert
}
outdata, err := services.Get(benchmarkRepo, "benchmarkBlob")
if !bytes.Equal(indata, outdata) || err != nil {
b.Fatalf("\tExpected: %s\n\tActual: %s\n\tErr:%s\n",
indata, outdata, err)
}
}
示例14: GetKey
func (gds googledriveservice) GetKey(h objects.HKID) (b objects.Blob, err error) {
if gds.driveService == nil {
return nil, fmt.Errorf("Drive Service not initialized")
}
fileID, err := gds.getChildWithTitle(gds.keysFolderID, h.Hex())
f, err := gds.driveService.Files.Get(fileID).Do()
fileString, err := gds.DownloadFile(f)
if err != nil {
log.Printf("An error occurred: %v\n", err)
return nil, err
}
log.Printf("Key %s:\n%q", h, fileString)
return objects.Blob(fileString), err
}
示例15: GetBlob
func (d directhttpservice) GetBlob(h objects.HCID) (objects.Blob, error) {
for _, host := range hosts {
quarryurl := fmt.Sprintf(
"https://%s/b/%s",
host,
h.Hex(),
)
body, err := urlReadAll(quarryurl)
if err != nil {
return objects.Blob{}, err
}
return objects.Blob(body), err
}
return objects.Blob{}, fmt.Errorf("No Hosts")
}