Documentation
¶
Index ¶
- Constants
- Variables
- type Bucket
- func (b *Bucket) DownloadToStream(fileID interface{}, stream io.Writer) (int64, error)
- func (b *Bucket) DownloadToStreamByName(filename string, stream io.Writer, opts ...*options.NameOptions) (int64, error)
- func (b *Bucket) OpenDownloadStream(fileID interface{}) (*File, error)
- func (b *Bucket) OpenDownloadStreamByName(filename string, opts ...*options.NameOptions) (*File, error)
- func (b *Bucket) OpenUploadStream(filename string, opts ...*options.UploadOptions) (*File, error)
- func (b *Bucket) OpenUploadStreamWithID(fileID interface{}, filename string, opts ...*options.UploadOptions) (*File, error)
- func (b *Bucket) SetOpenDeadline(t time.Time) error
- func (b *Bucket) SetReadDeadline(t time.Time) error
- func (b *Bucket) SetWriteDeadline(t time.Time) error
- func (b *Bucket) UploadFromStream(filename string, source io.Reader, opts ...*options.UploadOptions) (primitive.ObjectID, error)
- func (b *Bucket) UploadFromStreamWithID(fileID interface{}, filename string, source io.Reader, ...) error
- type File
- func (f *File) Close() (err error)
- func (f *File) MD5Hash() (md5Hash string, err error)
- func (f *File) Name() (name string)
- func (f *File) Read(b []byte) (n int, err error)
- func (f *File) ReadAt(b []byte, off int64) (n int, err error)
- func (f *File) Seek(offset int64, whence int) (ret int64, err error)
- func (f *File) Write(b []byte) (n int, err error)
- func (f *File) WriteAt(b []byte, off int64) (n int, err error)
- func (f *File) WriteString(s string) (n int, err error)
- type FileInfo
- type FileReference
- type Hashes
Constants ¶
const ( // DefaultBucketName is the default name of bucket. DefaultBucketName string = "fs" // DefaultChunkSize is the default size of each file chunk. DefaultChunkSize int32 = 255 * 1024 // 255KiB )
const ( // StreamCreated equal 1 if stream buffer has been modified StreamCreated uint8 = 1 << 0 // StreamClosed equal 1 if stream closed StreamClosed uint8 = 1 << 1 // StreamRead equal 1 if stream can be read StreamRead uint8 = 1 << 2 // StreamWrite equal 1 if stream can be wrote StreamWrite uint8 = 1 << 3 // StreamModified equal 1 if stream buffer has been modified StreamModified uint8 = 1 << 4 )
Variables ¶
var ( // ErrFileNotFound occurs if a user asks to download a file with a file ID that isn't found in the files collection. ErrFileNotFound = errors.New("file with given parameters not found") // ErrWrongIndex is used when the chunk retrieved from the server does not have the expected index. ErrWrongIndex = errors.New("chunk index does not match expected index") // ErrWrongSize is used when the chunk retrieved from the server does not have the expected size. ErrWrongSize = errors.New("chunk size does not match expected size") // ErrFileInvalid indicates an invalid argument. // Methods on File will return this error when the receiver is nil. ErrFileInvalid = errors.New("invalid argument") // ErrStreamClosed is an error returned if an operation is attempted on a closed/aborted stream. ErrStreamClosed = errors.New("stream is closed or aborted") // ErrStreamSeekUnsupport is an error returned if unsupported whence value. ErrStreamSeekUnsupport = errors.New("unsupported whence value") // ErrStreamSeekOverflow is an error returned if seek past end of file. ErrStreamSeekOverflow = errors.New("seek past end of file") // ErrStreamPermission is an error returned if an operation is attempted on a not readable/writable stream. ErrStreamPermission = errors.New("stream is not readable or writable") )
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket represents a GridFS bucket.
func NewBucket ¶
func NewBucket(db *mongo.Database, opts ...*options.BucketOptions) *Bucket
NewBucket creates a GridFS bucket.
func (*Bucket) DownloadToStream ¶
DownloadToStream downloads the file with the specified fileID and writes it to the provided io.Writer. Returns the number of bytes written to the steam and an error, or nil if there was no error.
func (*Bucket) DownloadToStreamByName ¶
func (b *Bucket) DownloadToStreamByName(filename string, stream io.Writer, opts ...*options.NameOptions) (int64, error)
DownloadToStreamByName downloads the file with the given name to the given io.Writer.
func (*Bucket) OpenDownloadStream ¶
OpenDownloadStream creates a stream from which the contents of the file can be read and seek.
func (*Bucket) OpenDownloadStreamByName ¶
func (b *Bucket) OpenDownloadStreamByName(filename string, opts ...*options.NameOptions) (*File, error)
OpenDownloadStreamByName opens a download stream for the file with the given filename.
func (*Bucket) OpenUploadStream ¶
OpenUploadStream creates a file ID new upload stream for a file given the filename.
func (*Bucket) OpenUploadStreamWithID ¶
func (b *Bucket) OpenUploadStreamWithID(fileID interface{}, filename string, opts ...*options.UploadOptions) (*File, error)
OpenUploadStreamWithID creates a new upload stream for a file given the file ID and filename.
func (*Bucket) SetOpenDeadline ¶
SetOpenDeadline sets the open deadline for this bucket
func (*Bucket) SetReadDeadline ¶
SetReadDeadline sets the read deadline for this bucket
func (*Bucket) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline for this bucket.
func (*Bucket) UploadFromStream ¶
func (b *Bucket) UploadFromStream(filename string, source io.Reader, opts ...*options.UploadOptions) (primitive.ObjectID, error)
UploadFromStream creates a fileID and uploads a file given a source stream.
func (*Bucket) UploadFromStreamWithID ¶
func (b *Bucket) UploadFromStreamWithID(fileID interface{}, filename string, source io.Reader, opts ...*options.UploadOptions) error
UploadFromStreamWithID uploads a file given a source stream.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents an open file descriptor.
func (*File) Close ¶
Close closes the File, rendering it unusable for I/O. On files that support SetDeadline, any pending I/O operations will be canceled and return immediately with an error. Close will return an error if it has already been called.
func (*File) Read ¶
Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.
func (*File) ReadAt ¶
ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(b). At end of file, that error is io.EOF.
func (*File) Seek ¶
Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. The behavior of Seek on a file opened with O_APPEND is not specified.
func (*File) Write ¶
Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).
type FileInfo ¶
type FileInfo struct {
ID interface{} `bson:"_id"`
ChunkSize int32 `bson:"chunkSize"`
Filename string `bson:"filename"`
Length int64 `bson:"length"`
Metadata interface{} `bson:"metadata"`
Reference *FileReference `bson:"reference,omitempty"`
UploadDate time.Time `bson:"uploadDate"`
// contains filtered or unexported fields
}
FileInfo represents an database file descriptor.
type FileReference ¶
type FileReference struct {
Hashes Hashes `bson:"hashes,omitempty"`
MimeType string `bson:"mimeType,omitempty"`
CreatedDateTime time.Time `bson:"createdDateTime,omitempty"`
LastAccessedDateTime time.Time `bson:"lastAccessedDateTime,omitempty"`
LastModifiedDateTime time.Time `bson:"lastModifiedDateTime,omitempty"`
}
FileReference represents an database file reference.
type Hashes ¶
type Hashes struct {
MD5Hash *string `bson:"md5Hash,omitempty"` // hex
CRC32Hash *string `bson:"crc32Hash,omitempty"` // hex
SHA1Hash *string `bson:"sha1Hash,omitempty"` // hex
QuickXorHash *string `bson:"quickXorHash,omitempty"` // base64
}
Hashes represents an database file reference.