Documentation ¶
Index ¶
- Constants
- Variables
- type Bucket
- func (b *Bucket) Delete(fileID objectid.ObjectID) error
- func (b *Bucket) DownloadToStream(fileID objectid.ObjectID, stream io.Writer) (int64, error)
- func (b *Bucket) DownloadToStreamByName(filename string, stream io.Writer, opts ...NameOptioner) (int64, error)
- func (b *Bucket) Drop() error
- func (b *Bucket) Find(filter interface{}, opts ...FindOptioner) (mongo.Cursor, error)
- func (b *Bucket) OpenDownloadStream(fileID objectid.ObjectID) (*DownloadStream, error)
- func (b *Bucket) OpenDownloadStreamByName(filename string, opts ...NameOptioner) (*DownloadStream, error)
- func (b *Bucket) OpenUploadStream(filename string, opts ...UploadOptioner) (*UploadStream, error)
- func (b *Bucket) OpenUploadStreamWithID(fileID objectid.ObjectID, filename string, opts ...UploadOptioner) (*UploadStream, error)
- func (b *Bucket) Rename(fileID objectid.ObjectID, newFilename string) 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 ...UploadOptioner) (objectid.ObjectID, error)
- func (b *Bucket) UploadFromStreamWithID(fileID objectid.ObjectID, filename string, source io.Reader, ...) error
- type BucketBundle
- func (bb *BucketBundle) BucketName(name string) *BucketBundle
- func (bb *BucketBundle) ChunkSizeBytes(b int32) *BucketBundle
- func (bb *BucketBundle) ReadConcern(rc *readconcern.ReadConcern) *BucketBundle
- func (bb *BucketBundle) ReadPreference(rp *readpref.ReadPref) *BucketBundle
- func (bb *BucketBundle) Unbundle(deduplicate bool) ([]BucketOptioner, error)
- func (bb *BucketBundle) WriteConcern(wc *writeconcern.WriteConcern) *BucketBundle
- type BucketOptioner
- type DownloadStream
- type FindBundle
- func (fb *FindBundle) BatchSize(i int32) *FindBundle
- func (fb *FindBundle) Limit(i int32) *FindBundle
- func (fb *FindBundle) MaxTime(d time.Duration) *FindBundle
- func (fb *FindBundle) NoCursorTimeout(b bool) *FindBundle
- func (fb *FindBundle) Skip(i int32) *FindBundle
- func (fb *FindBundle) Sort(sort interface{}) *FindBundle
- func (fb *FindBundle) Unbundle(deduplicate bool) ([]FindOptioner, error)
- type FindOptioner
- type NameBundle
- type NameOptioner
- type OptBatchSize
- type OptBucketName
- type OptChunkSizeBytes
- type OptLimit
- type OptMaxTime
- type OptMetadata
- type OptNoCursorTimeout
- type OptReadConcern
- type OptReadPreference
- type OptRevision
- type OptSkip
- type OptSort
- type OptWriteConcern
- type Upload
- type UploadBundle
- type UploadOptioner
- type UploadStream
Constants ¶
const DefaultChunkSize int32 = 255 * 1000 // 255 KB
DefaultChunkSize is the default size of each file chunk.
const UploadBufferSize = 16 * 1000000 // 16 MB
UploadBufferSize is the size in bytes of one stream batch. Chunks will be written to the db after the sum of chunk lengths is equal to the batch size.
Variables ¶
var ErrFileNotFound = errors.New("file with given parameters not found")
ErrFileNotFound occurs if a user asks to download a file with a file ID that isn't found in the files collection.
var ErrStreamClosed = errors.New("stream is closed or aborted")
ErrStreamClosed is an error returned if an operation is attempted on a closed/aborted stream.
var ErrWrongIndex = errors.New("chunk index does not match expected index")
ErrWrongIndex is used when the chunk retrieved from the server does not have the expected index.
var ErrWrongSize = errors.New("chunk size does not match expected size")
ErrWrongSize is used when the chunk retrieved from the server does not have the expected size.
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 ...BucketOptioner) (*Bucket, error)
NewBucket creates a GridFS bucket.
func (*Bucket) Delete ¶
Delete deletes all chunks and metadata associated with the file with the given file ID.
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 ...NameOptioner) (int64, error)
DownloadToStreamByName downloads the file with the given name to the given io.Writer.
func (*Bucket) Find ¶
func (b *Bucket) Find(filter interface{}, opts ...FindOptioner) (mongo.Cursor, error)
Find returns the files collection documents that match the given filter.
func (*Bucket) OpenDownloadStream ¶
func (b *Bucket) OpenDownloadStream(fileID objectid.ObjectID) (*DownloadStream, error)
OpenDownloadStream creates a stream from which the contents of the file can be read.
func (*Bucket) OpenDownloadStreamByName ¶
func (b *Bucket) OpenDownloadStreamByName(filename string, opts ...NameOptioner) (*DownloadStream, error)
OpenDownloadStreamByName opens a download stream for the file with the given filename.
func (*Bucket) OpenUploadStream ¶
func (b *Bucket) OpenUploadStream(filename string, opts ...UploadOptioner) (*UploadStream, error)
OpenUploadStream creates a file ID new upload stream for a file given the filename.
func (*Bucket) OpenUploadStreamWithID ¶
func (b *Bucket) OpenUploadStreamWithID(fileID objectid.ObjectID, filename string, opts ...UploadOptioner) (*UploadStream, error)
OpenUploadStreamWithID creates a new upload stream for a file given the file ID and filename.
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 ...UploadOptioner) (objectid.ObjectID, error)
UploadFromStream creates a fileID and uploads a file given a source stream.
func (*Bucket) UploadFromStreamWithID ¶
func (b *Bucket) UploadFromStreamWithID(fileID objectid.ObjectID, filename string, source io.Reader, opts ...UploadOptioner) error
UploadFromStreamWithID uploads a file given a source stream.
type BucketBundle ¶
type BucketBundle struct {
// contains filtered or unexported fields
}
BucketBundle is a bundle of BucketOptioner options
func BundleBucket ¶
func BundleBucket(opts ...BucketOptioner) *BucketBundle
BundleBucket bundles BucketOptioner options.
func (*BucketBundle) BucketName ¶
func (bb *BucketBundle) BucketName(name string) *BucketBundle
BucketName specifies the name of the bucket. Defaults to 'fs' if not specified.
func (*BucketBundle) ChunkSizeBytes ¶
func (bb *BucketBundle) ChunkSizeBytes(b int32) *BucketBundle
ChunkSizeBytes specifies the chunk size for the bucket. Defaults to 255KB if not specified.
func (*BucketBundle) ReadConcern ¶
func (bb *BucketBundle) ReadConcern(rc *readconcern.ReadConcern) *BucketBundle
ReadConcern specifies the read concern for the bucket.
func (*BucketBundle) ReadPreference ¶
func (bb *BucketBundle) ReadPreference(rp *readpref.ReadPref) *BucketBundle
ReadPreference specifies the read preference for the bucket.
func (*BucketBundle) Unbundle ¶
func (bb *BucketBundle) Unbundle(deduplicate bool) ([]BucketOptioner, error)
Unbundle transforms a bundle into a slice of BucketOptioner options, deduplicating if specified.
func (*BucketBundle) WriteConcern ¶
func (bb *BucketBundle) WriteConcern(wc *writeconcern.WriteConcern) *BucketBundle
WriteConcern specifies the write concern for the bucket.
type BucketOptioner ¶
type BucketOptioner interface {
// contains filtered or unexported methods
}
BucketOptioner represents all options that can be used to configure a GridFS bucket.
type DownloadStream ¶
type DownloadStream struct {
// contains filtered or unexported fields
}
DownloadStream is a io.Reader that can be used to download a file from a GridFS bucket.
func (*DownloadStream) Close ¶
func (ds *DownloadStream) Close() error
Close closes this download stream.
func (*DownloadStream) Read ¶
func (ds *DownloadStream) Read(p []byte) (int, error)
Read reads the file from the server and writes it to a destination byte slice.
func (*DownloadStream) SetReadDeadline ¶
func (ds *DownloadStream) SetReadDeadline(t time.Time) error
SetReadDeadline sets the read deadline for this download stream.
type FindBundle ¶
type FindBundle struct {
// contains filtered or unexported fields
}
FindBundle represents a bundle of GridFS Find options.
func BundleFind ¶
func BundleFind(opts ...FindOptioner) *FindBundle
BundleFind bundles FindOptioner options.
func (*FindBundle) BatchSize ¶
func (fb *FindBundle) BatchSize(i int32) *FindBundle
BatchSize specifies the number of documents to return per batch.
func (*FindBundle) Limit ¶
func (fb *FindBundle) Limit(i int32) *FindBundle
Limit specifies the maximum number of documents to return.
func (*FindBundle) MaxTime ¶
func (fb *FindBundle) MaxTime(d time.Duration) *FindBundle
MaxTime specifies the maximum amount of time to allow the query to run.
func (*FindBundle) NoCursorTimeout ¶
func (fb *FindBundle) NoCursorTimeout(b bool) *FindBundle
NoCursorTimeout specifies that the server should not time out after an inactivity period.
func (*FindBundle) Skip ¶
func (fb *FindBundle) Skip(i int32) *FindBundle
Skip specifies the number of documents to skip before returning.
func (*FindBundle) Sort ¶
func (fb *FindBundle) Sort(sort interface{}) *FindBundle
Sort specifies the order by which to sort results.
func (*FindBundle) Unbundle ¶
func (fb *FindBundle) Unbundle(deduplicate bool) ([]FindOptioner, error)
Unbundle transforms a bundle into a slice of BucketOptioner options, deduplicating if specified.
type FindOptioner ¶
type FindOptioner interface {
// contains filtered or unexported methods
}
FindOptioner represents all options that can be used to configure a find command.
type NameBundle ¶
type NameBundle struct {
// contains filtered or unexported fields
}
NameBundle bundles valid options for download by name commands.
func BundleName ¶
func BundleName(opts ...NameOptioner) *NameBundle
BundleName bundles NameOptioner options.
func (*NameBundle) Revision ¶
func (nb *NameBundle) Revision(i int32) *NameBundle
Revision specifies which revision of the file to retrieve. Defaults to -1. * Revision numbers are defined as follows: * 0 = the original stored file * 1 = the first revision * 2 = the second revision * etc… * -2 = the second most recent revision * -1 = the most recent revision
func (*NameBundle) Unbundle ¶
func (nb *NameBundle) Unbundle(deduplicate bool) ([]NameOptioner, error)
Unbundle transforms a bundle into a slice of BucketOptioner options, deduplicating if specified.
type NameOptioner ¶
type NameOptioner interface {
// contains filtered or unexported methods
}
NameOptioner represents all options that can be used for a download by name command.
type OptBatchSize ¶
type OptBatchSize int32
OptBatchSize specifies the number of documents to return per batch.
func BatchSize ¶
func BatchSize(i int32) OptBatchSize
BatchSize specifies the number of documents to return per batch.
type OptBucketName ¶
type OptBucketName string
OptBucketName specifies the name of the bucket. Defaults to 'fs' if not specified.
func BucketName ¶
func BucketName(name string) OptBucketName
BucketName specifies the name of the bucket. Defaults to 'fs' if not specified.
type OptChunkSizeBytes ¶
type OptChunkSizeBytes int32
OptChunkSizeBytes specifies the chunk size for the bucket. Defaults to 255KB if not specified.
func ChunkSizeBytes ¶
func ChunkSizeBytes(b int32) OptChunkSizeBytes
ChunkSizeBytes specifies the chunk size for the bucket. Defaults to 255KB if not specified.
type OptMaxTime ¶
OptMaxTime specifies the maximum amount of time to allow the query to run.
func MaxTime ¶
func MaxTime(d time.Duration) OptMaxTime
MaxTime specifies the maximum amount of time to allow the query to run.
type OptMetadata ¶
OptMetadata specifies the metadata for a file upload.
func Metadata ¶
func Metadata(doc *bson.Document) OptMetadata
Metadata specifies the metadata for a file upload.
type OptNoCursorTimeout ¶
type OptNoCursorTimeout bool
OptNoCursorTimeout specifies that the server should not time out after an inactivity period.
func NoCursorTimeout ¶
func NoCursorTimeout(b bool) OptNoCursorTimeout
NoCursorTimeout specifies that the server should not time out after an inactivity period.
type OptReadConcern ¶
type OptReadConcern struct {
*readconcern.ReadConcern
}
OptReadConcern specifies the read concern for the bucket.
func ReadConcern ¶
func ReadConcern(rc *readconcern.ReadConcern) OptReadConcern
ReadConcern specifies the read concern for the bucket.
type OptReadPreference ¶
OptReadPreference specifies the read preference for the bucket.
func ReadPreference ¶
func ReadPreference(rp *readpref.ReadPref) OptReadPreference
ReadPreference specifies the read preference for the bucket.
type OptRevision ¶
type OptRevision int32
OptRevision specifies which revision of the file to retrieve. Defaults to -1. * Revision numbers are defined as follows: * 0 = the original stored file * 1 = the first revision * 2 = the second revision * etc… * -2 = the second most recent revision * -1 = the most recent revision
func Revision ¶
func Revision(i int32) OptRevision
Revision specifies which revision of the file to retrieve. Defaults to -1. * Revision numbers are defined as follows: * 0 = the original stored file * 1 = the first revision * 2 = the second revision * etc… * -2 = the second most recent revision * -1 = the most recent revision
type OptSkip ¶
type OptSkip int32
OptSkip specifies the number of documents to skip before returning.
type OptSort ¶
type OptSort struct {
Sort interface{}
}
OptSort specifies the order by which to sort results.
type OptWriteConcern ¶
type OptWriteConcern struct {
*writeconcern.WriteConcern
}
OptWriteConcern specifies the write concern for the bucket.
func WriteConcern ¶
func WriteConcern(wc *writeconcern.WriteConcern) OptWriteConcern
WriteConcern specifies the write concern for the bucket.
type Upload ¶
type Upload struct {
// contains filtered or unexported fields
}
Upload contains options to upload a file to a bucket.
type UploadBundle ¶
type UploadBundle struct {
// contains filtered or unexported fields
}
UploadBundle is a bundle of UploadOptioner options.
func BundleUpload ¶
func BundleUpload(opts ...UploadOptioner) *UploadBundle
BundleUpload bundles UploadOptioner options.
func (*UploadBundle) ChunkSizeBytes ¶
func (ub *UploadBundle) ChunkSizeBytes(b int32) *UploadBundle
ChunkSizeBytes specifies the chunk size for the bucket. Defaults to 255KB if not specified.
func (*UploadBundle) Metadata ¶
func (ub *UploadBundle) Metadata(doc *bson.Document) *UploadBundle
Metadata specifies the metadata for a file upload.
func (*UploadBundle) Unbundle ¶
func (ub *UploadBundle) Unbundle(deduplicate bool) ([]UploadOptioner, error)
Unbundle transforms a bundle into a slice of BucketOptioner options, deduplicating if specified.
type UploadOptioner ¶
type UploadOptioner interface {
// contains filtered or unexported methods
}
UploadOptioner represents all options that can be used to configure a file upload.
type UploadStream ¶
type UploadStream struct { *Upload // chunk size and metadata FileID objectid.ObjectID // contains filtered or unexported fields }
UploadStream is used to upload files in chunks.
func (*UploadStream) Abort ¶
func (us *UploadStream) Abort() error
Abort closes the stream and deletes all file chunks that have already been written.
func (*UploadStream) SetWriteDeadline ¶
func (us *UploadStream) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the write deadline for this stream.