// Repeatedly call bucket.ListObjects until there is nothing further to list, // returning all objects and collapsed runs encountered. // // May modify *req. func ListAll( ctx context.Context, bucket gcs.Bucket, req *gcs.ListObjectsRequest) ( objects []*gcs.Object, runs []string, err error) { for { // Grab one set of results. var listing *gcs.Listing if listing, err = bucket.ListObjects(ctx, req); err != nil { return } // Accumulate the results. objects = append(objects, listing.Objects...) runs = append(runs, listing.CollapsedRuns...) // Are we done? if listing.ContinuationToken == "" { break } req.ContinuationToken = listing.ContinuationToken } return }
func (b *prefixBucket) ListObjects( ctx context.Context, req *gcs.ListObjectsRequest) (l *gcs.Listing, err error) { // Modify the request and call through. mReq := new(gcs.ListObjectsRequest) *mReq = *req mReq.Prefix = b.prefix + mReq.Prefix l, err = b.wrapped.ListObjects(ctx, mReq) // Modify the returned listing. if l != nil { for _, o := range l.Objects { o.Name = b.localName(o.Name) } for i, n := range l.CollapsedRuns { l.CollapsedRuns[i] = strings.TrimPrefix(n, b.prefix) } } return }