本文整理汇总了Golang中github.com/jacobsa/gcloud/gcs/gcsutil.ReadObject函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadObject函数的具体用法?Golang ReadObject怎么用?Golang ReadObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BucketsAreSegregatedByName
func (t *ConnTest) BucketsAreSegregatedByName() {
const objName = "baz"
var contents []byte
var err error
b0, err := t.conn.OpenBucket(t.ctx, "foo")
AssertEq(nil, err)
b1, err := t.conn.OpenBucket(t.ctx, "bar")
AssertEq(nil, err)
// Add an object with the same name but different contents to each of two
// buckets.
_, err = gcsutil.CreateObject(t.ctx, b0, objName, []byte("taco"))
AssertEq(nil, err)
_, err = gcsutil.CreateObject(t.ctx, b1, objName, []byte("burrito"))
AssertEq(nil, err)
// Each should have stored it independently.
contents, err = gcsutil.ReadObject(t.ctx, b0, objName)
AssertEq(nil, err)
ExpectEq("taco", string(contents))
contents, err = gcsutil.ReadObject(t.ctx, b1, objName)
AssertEq(nil, err)
ExpectEq("burrito", string(contents))
}
示例2: CopyObject
func (t *PrefixBucketTest) CopyObject() {
var err error
suffix := "taco"
name := t.prefix + suffix
contents := "foobar"
// Create an object through the back door.
_, err = gcsutil.CreateObject(t.ctx, t.wrapped, name, []byte(contents))
AssertEq(nil, err)
// Copy it to a new name.
newSuffix := "burrito"
o, err := t.bucket.CopyObject(
t.ctx,
&gcs.CopyObjectRequest{
SrcName: suffix,
DstName: newSuffix,
})
AssertEq(nil, err)
ExpectEq(newSuffix, o.Name)
// Read it through the back door.
actual, err := gcsutil.ReadObject(t.ctx, t.wrapped, t.prefix+newSuffix)
AssertEq(nil, err)
ExpectEq(contents, string(actual))
}
示例3: BucketContentsAreStable
func (t *ConnTest) BucketContentsAreStable() {
const bucketName = "foo"
const objName = "bar"
var err error
// Open the bucket.
bucket, err := t.conn.OpenBucket(t.ctx, bucketName)
AssertEq(nil, err)
// Add an object to a bucket.
_, err = gcsutil.CreateObject(
t.ctx,
bucket,
objName,
[]byte("taco"))
AssertEq(nil, err)
// Grab the bucket again. It should still be there.
contents, err := gcsutil.ReadObject(
t.ctx,
bucket,
objName)
AssertEq(nil, err)
ExpectEq("taco", string(contents))
}
示例4: BasicUsage
func (t *MountTest) BasicUsage() {
var err error
const fileName = "foo"
// Grab a bucket.
bucket, err := t.conn.OpenBucket(t.ctx, "some_bucket")
AssertEq(nil, err)
// Mount that bucket.
mfs, err := t.mount(bucket.Name(), t.dir)
AssertEq(nil, err)
// Create a file.
err = ioutil.WriteFile(path.Join(t.dir, fileName), []byte("taco"), 0400)
AssertEq(nil, err)
// Read the object from the bucket.
contents, err := gcsutil.ReadObject(t.ctx, bucket, fileName)
AssertEq(nil, err)
ExpectEq("taco", string(contents))
// Read the file.
contents, err = ioutil.ReadFile(path.Join(t.dir, fileName))
AssertEq(nil, err)
ExpectEq("taco", string(contents))
// Unmount and join.
err = t.unmount()
AssertEq(nil, err)
err = mfs.Join(t.ctx)
AssertEq(nil, err)
}
示例5: TruncateThenSync
func (t *IntegrationTest) TruncateThenSync() {
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
AssertEq(nil, err)
t.create(o)
// Truncate.
err = t.mc.Truncate(t.ctx, 2)
AssertEq(nil, err)
// Sync should save out the new generation.
rl, newObj, err := t.sync(o)
AssertEq(nil, err)
ExpectNe(o.Generation, newObj.Generation)
ExpectEq(t.objectGeneration("foo"), newObj.Generation)
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
AssertEq(nil, err)
ExpectEq("ta", string(contents))
// Read via the lease.
_, err = rl.Seek(0, 0)
AssertEq(nil, err)
contents, err = ioutil.ReadAll(rl)
AssertEq(nil, err)
ExpectEq("ta", string(contents))
}
示例6: TruncateThenSync
func (t *IntegrationTest) TruncateThenSync() {
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", []byte("taco"))
AssertEq(nil, err)
t.create(o)
// Truncate.
t.clock.AdvanceTime(time.Second)
truncateTime := t.clock.Now()
err = t.tf.Truncate(2)
t.clock.AdvanceTime(time.Second)
AssertEq(nil, err)
// Sync should save out the new generation.
newObj, err := t.sync(o)
AssertEq(nil, err)
ExpectNe(o.Generation, newObj.Generation)
ExpectEq(t.objectGeneration("foo"), newObj.Generation)
ExpectEq(
truncateTime.UTC().Format(time.RFC3339Nano),
newObj.Metadata["gcsfuse_mtime"])
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
AssertEq(nil, err)
ExpectEq("ta", string(contents))
}
示例7: WithinLeaserLimit
func (t *IntegrationTest) WithinLeaserLimit() {
AssertLt(len("taco"), fileLeaserLimitBytes)
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
AssertEq(nil, err)
t.create(o)
// Extend to be up against the leaser limit, then write out to GCS, which
// should downgrade to a read lease.
err = t.mc.Truncate(t.ctx, fileLeaserLimitBytes)
AssertEq(nil, err)
rl, _, err := t.sync(o)
AssertEq(nil, err)
// The backing object should be present and contain the correct contents.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, o.Name)
AssertEq(nil, err)
ExpectEq(fileLeaserLimitBytes, len(contents))
// Delete the backing object.
err = t.bucket.DeleteObject(t.ctx, &gcs.DeleteObjectRequest{Name: o.Name})
AssertEq(nil, err)
// We should still be able to read the contents, because the read lease
// should still be valid.
buf := make([]byte, 4)
n, err := rl.ReadAt(buf, 0)
AssertEq(nil, err)
ExpectEq("taco", string(buf[0:n]))
}
示例8: LargerThanLeaserLimit
func (t *IntegrationTest) LargerThanLeaserLimit() {
AssertLt(len("taco"), fileLeaserLimitBytes)
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
AssertEq(nil, err)
t.create(o)
// Extend to be past the leaser limit, then write out to GCS, which should
// downgrade to a read lease.
err = t.mc.Truncate(t.ctx, fileLeaserLimitBytes+1)
AssertEq(nil, err)
rl, _, err := t.sync(o)
AssertEq(nil, err)
// The backing object should be present and contain the correct contents.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, o.Name)
AssertEq(nil, err)
ExpectEq(fileLeaserLimitBytes+1, len(contents))
// Delete the backing object.
err = t.bucket.DeleteObject(t.ctx, &gcs.DeleteObjectRequest{Name: o.Name})
AssertEq(nil, err)
// The contents should be lost, because the leaser should have revoked the
// read lease.
_, err = rl.ReadAt(make([]byte, len(contents)), 0)
ExpectThat(err, Error(HasSubstr("revoked")))
}
示例9: CloneToChildFile_DestinationExists
func (t *DirTest) CloneToChildFile_DestinationExists() {
const srcName = "blah/baz"
dstName := path.Join(dirInodeName, "qux")
var o *gcs.Object
var err error
// Create the source.
src, err := gcsutil.CreateObject(t.ctx, t.bucket, srcName, []byte("taco"))
AssertEq(nil, err)
// And a destination object that will be overwritten.
_, err = gcsutil.CreateObject(t.ctx, t.bucket, dstName, []byte(""))
AssertEq(nil, err)
// Call the inode.
o, err = t.in.CloneToChildFile(t.ctx, path.Base(dstName), src)
AssertEq(nil, err)
AssertNe(nil, o)
ExpectEq(dstName, o.Name)
ExpectFalse(inode.IsSymlink(o))
ExpectEq(len("taco"), o.Size)
// Check resulting contents.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, dstName)
AssertEq(nil, err)
ExpectEq("taco", string(contents))
}
示例10: DeleteFile
func (t *ReadOnlyTest) DeleteFile() {
// Create an object in the bucket.
_, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
AssertEq(nil, err)
// Attempt to delete it via the file system.
err = os.Remove(path.Join(t.Dir, "foo"))
ExpectThat(err, Error(HasSubstr("read-only")))
// the bucket should not have been modified.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
AssertEq(nil, err)
ExpectEq("taco", string(contents))
}
示例11: AppendThenSync
func (t *FileTest) AppendThenSync() {
var attrs fuseops.InodeAttributes
var err error
AssertEq("taco", t.initialContents)
// Append some data.
t.clock.AdvanceTime(time.Second)
writeTime := t.clock.Now()
err = t.in.Write(t.ctx, []byte("burrito"), int64(len("taco")))
AssertEq(nil, err)
t.clock.AdvanceTime(time.Second)
// Sync.
err = t.in.Sync(t.ctx)
AssertEq(nil, err)
// The generation should have advanced.
ExpectLt(t.backingObj.Generation, t.in.SourceGeneration().Object)
// Stat the current object in the bucket.
statReq := &gcs.StatObjectRequest{Name: t.in.Name()}
o, err := t.bucket.StatObject(t.ctx, statReq)
AssertEq(nil, err)
ExpectEq(t.in.SourceGeneration().Object, o.Generation)
ExpectEq(t.in.SourceGeneration().Metadata, o.MetaGeneration)
ExpectEq(len("tacoburrito"), o.Size)
ExpectEq(
writeTime.UTC().Format(time.RFC3339Nano),
o.Metadata["gcsfuse_mtime"])
// Read the object's contents.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, t.in.Name())
AssertEq(nil, err)
ExpectEq("tacoburrito", string(contents))
// Check attributes.
attrs, err = t.in.Attributes(t.ctx)
AssertEq(nil, err)
ExpectEq(len("tacoburrito"), attrs.Size)
ExpectThat(attrs.Mtime, timeutil.TimeEq(writeTime.UTC()))
}
示例12: AppendThenSync
func (t *IntegrationTest) AppendThenSync() {
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
AssertEq(nil, err)
t.create(o)
// Append some data.
n, err := t.mc.WriteAt(t.ctx, []byte("burrito"), 4)
AssertEq(nil, err)
ExpectEq(len("burrito"), n)
// Sync should save out the new generation.
rl, newObj, err := t.sync(o)
AssertEq(nil, err)
ExpectNe(o.Generation, newObj.Generation)
ExpectEq(t.objectGeneration("foo"), newObj.Generation)
// Read via the bucket.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
AssertEq(nil, err)
ExpectEq("tacoburrito", string(contents))
// Read via the lease.
_, err = rl.Seek(0, 0)
AssertEq(nil, err)
contents, err = ioutil.ReadAll(rl)
AssertEq(nil, err)
ExpectEq("tacoburrito", string(contents))
// There should be no junk left over in the bucket besides the object of
// interest.
objects, runs, err := gcsutil.ListAll(
t.ctx,
t.bucket,
&gcs.ListObjectsRequest{})
AssertEq(nil, err)
AssertEq(1, len(objects))
AssertEq(0, len(runs))
ExpectEq("foo", objects[0].Name)
}
示例13: DeleteChildDir_Exists
func (t *DirTest) DeleteChildDir_Exists() {
const name = "qux"
objName := path.Join(dirInodeName, name) + "/"
var err error
// Create a backing object.
_, err = gcsutil.CreateObject(t.ctx, t.bucket, objName, []byte("taco"))
AssertEq(nil, err)
// Call the inode.
err = t.in.DeleteChildDir(t.ctx, name)
AssertEq(nil, err)
// Check the bucket.
_, err = gcsutil.ReadObject(t.ctx, t.bucket, objName)
ExpectThat(err, HasSameTypeAs(&gcs.NotFoundError{}))
}
示例14: DeleteChildFile_ParticularGenerationAndMetaGeneration
func (t *DirTest) DeleteChildFile_ParticularGenerationAndMetaGeneration() {
const name = "qux"
objName := path.Join(dirInodeName, name)
var err error
// Create a backing object.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, objName, []byte("taco"))
AssertEq(nil, err)
// Call the inode.
err = t.in.DeleteChildFile(t.ctx, name, o.Generation, &o.MetaGeneration)
AssertEq(nil, err)
// Check the bucket.
_, err = gcsutil.ReadObject(t.ctx, t.bucket, objName)
ExpectThat(err, HasSameTypeAs(&gcs.NotFoundError{}))
}
示例15: AppendThenSync
func (t *IntegrationTest) AppendThenSync() {
// Create.
o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", []byte("taco"))
AssertEq(nil, err)
t.create(o)
// Append some data.
t.clock.AdvanceTime(time.Second)
writeTime := t.clock.Now()
n, err := t.tf.WriteAt([]byte("burrito"), 4)
t.clock.AdvanceTime(time.Second)
AssertEq(nil, err)
ExpectEq(len("burrito"), n)
// Sync should save out the new generation.
newObj, err := t.sync(o)
AssertEq(nil, err)
ExpectNe(o.Generation, newObj.Generation)
ExpectEq(t.objectGeneration("foo"), newObj.Generation)
ExpectEq(
writeTime.UTC().Format(time.RFC3339Nano),
newObj.Metadata["gcsfuse_mtime"])
// Read via the bucket.
contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
AssertEq(nil, err)
ExpectEq("tacoburrito", string(contents))
// There should be no junk left over in the bucket besides the object of
// interest.
objects, runs, err := gcsutil.ListAll(
t.ctx,
t.bucket,
&gcs.ListObjectsRequest{})
AssertEq(nil, err)
AssertEq(1, len(objects))
AssertEq(0, len(runs))
ExpectEq("foo", objects[0].Name)
}