// NewBucket creates a GridFS bucket.
NewBucket creates a GridFS bucket.
// NewBucket creates a GridFS bucket .
func NewBucket(db *mongo.Database, opts ...*options.BucketOptions) (*Bucket, error) {
	b := &Bucket{
		name:      "fs",
		chunkSize: DefaultChunkSize,
		db:        db,
		wc:        db.WriteConcern(),
		rc:        db.ReadConcern(),
		rp:        db.ReadPreference(),
	}
	bo := options.MergeBucketOptions(opts...)
	if bo.Name != nil {
		b.name = *bo.Name
	}
	if bo.ChunkSizeBytes != nil {
		b.chunkSize = *bo.ChunkSizeBytes
	}
	if bo.WriteConcern != nil {
		b.wc = bo.WriteConcern
	}
	if bo.ReadConcern != nil {
		b.rc = bo.ReadConcern
	}
	if bo.ReadPreference != nil {
		b.rp = bo.ReadPreference
	}
	var collOpts = options.Collection().SetWriteConcern(b.wc).SetReadConcern(b.rc).SetReadPreference(b.rp)
	b.chunksColl = db.Collection(b.name+".chunks", collOpts)
	b.filesColl = db.Collection(b.name+".files", collOpts)
	b.readBuf = make([]byte, b.chunkSize)
	b.writeBuf = make([]byte, b.chunkSize)
	return b, nil
}
func NewBucket ( db * mongo . Database , opts ... * options . BucketOptions ) ( * Bucket , error ) { b := & Bucket { name : " " , chunkSize : DefaultChunkSize , db : db , wc : db . WriteConcern ( ) , rc : db . ReadConcern ( ) , rp : db . ReadPreference ( ) , } bo := options . MergeBucketOptions ( opts ... ) if bo . Name != nil { b . name = * bo . Name } if bo . ChunkSizeBytes != nil { b . chunkSize = * bo . ChunkSizeBytes } if bo . WriteConcern != nil { b . wc = bo . WriteConcern } if bo . ReadConcern != nil { b . rc = bo . ReadConcern } if bo . ReadPreference != nil { b . rp = bo . ReadPreference } var collOpts = options . Collection ( ) . SetWriteConcern ( b . wc ) . SetReadConcern ( b . rc ) . SetReadPreference ( b . rp ) b . chunksColl = db . Collection ( b . name + " " , collOpts ) b . filesColl = db . Collection ( b . name + " " , collOpts ) b . readBuf = make ( [ ] byte , b . chunkSize ) b . writeBuf = make ( [ ] byte , b . chunkSize ) return b , nil }
NewBucket creates a GridFS bucket.
NewBucket creates a GridFS bucket .