forked from GoogleCloudPlatform/gcsfuse
/
bucket.go
117 lines (105 loc) · 4.07 KB
/
bucket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2023 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gcs
import (
"io"
"golang.org/x/net/context"
)
// Bucket represents a GCS bucket, pre-bound with a bucket name and necessary
// authorization information.
//
// Each method that may block accepts a context object that is used for
// deadlines and cancellation. Users need not package authorization information
// into the context object (using cloud.WithContext or similar).
//
// All methods are safe for concurrent access.
type Bucket interface {
Name() string
// Create a reader for the contents of a particular generation of an object.
// On a nil error, the caller must arrange for the reader to be closed when
// it is no longer needed.
//
// Non-existent objects cause either this method or the first read from the
// resulting reader to return an error of type *NotFoundError.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/get
NewReader(
ctx context.Context,
req *ReadObjectRequest) (io.ReadCloser, error)
// Create or overwrite an object according to the supplied request. The new
// object is guaranteed to exist immediately for the purposes of reading (and
// eventually for listing) after this method returns a nil error. It is
// guaranteed not to exist before req.Contents returns io.EOF.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/insert
// https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload
CreateObject(
ctx context.Context,
req *CreateObjectRequest) (*Object, error)
// Copy an object to a new name, preserving all metadata. Any existing
// generation of the destination name will be overwritten.
//
// Returns a record for the new object.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/copy
CopyObject(
ctx context.Context,
req *CopyObjectRequest) (*Object, error)
// Compose one or more source objects into a single destination object by
// concatenating. Any existing generation of the destination name will be
// overwritten.
//
// Returns a record for the new object.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/compose
ComposeObjects(
ctx context.Context,
req *ComposeObjectsRequest) (*Object, error)
// Return current information about the object with the given name.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/get
StatObject(
ctx context.Context,
req *StatObjectRequest) (*MinObject, *ExtendedObjectAttributes, error)
// List the objects in the bucket that meet the criteria defined by the
// request, returning a result object that contains the results and
// potentially a cursor for retrieving the next portion of the larger set of
// results.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/list
ListObjects(
ctx context.Context,
req *ListObjectsRequest) (*Listing, error)
// Update the object specified by newAttrs.Name, patching using the non-zero
// fields of newAttrs.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/patch
UpdateObject(
ctx context.Context,
req *UpdateObjectRequest) (*Object, error)
// Delete an object. Non-existence of the object is not treated as an error.
//
// Official documentation:
// https://cloud.google.com/storage/docs/json_api/v1/objects/delete
DeleteObject(
ctx context.Context,
req *DeleteObjectRequest) error
}