github.com/cs3org/reva/v2@v2.27.7/pkg/sdk/common/datadesc.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package common 20 21 import ( 22 "os" 23 "time" 24 ) 25 26 // DataDescriptor implements os.FileInfo to provide file information for non-file data objects. 27 // This is used, for example, when uploading data that doesn't come from a local file. 28 type DataDescriptor struct { 29 name string 30 size int64 31 } 32 33 // Name returns the quasi-filename of this object. 34 func (ddesc *DataDescriptor) Name() string { 35 return ddesc.name 36 } 37 38 // Size returns the specified data size. 39 func (ddesc *DataDescriptor) Size() int64 { 40 return ddesc.size 41 } 42 43 // Mode always returns a 0700 file mode. 44 func (ddesc *DataDescriptor) Mode() os.FileMode { 45 return 0700 46 } 47 48 // ModTime always returns the current time as the modification time. 49 func (ddesc *DataDescriptor) ModTime() time.Time { 50 return time.Now() 51 } 52 53 // IsDir always returns false. 54 func (ddesc *DataDescriptor) IsDir() bool { 55 return false 56 } 57 58 // Sys returns nil, as this object doesn't represent a system object. 59 func (ddesc *DataDescriptor) Sys() interface{} { 60 return nil 61 } 62 63 // CreateDataDescriptor creates a new descriptor for non-file data objects. 64 func CreateDataDescriptor(name string, size int64) DataDescriptor { 65 return DataDescriptor{ 66 name: name, 67 size: size, 68 } 69 }