@@ -113,8 +113,8 @@ public ImmutableGridFSBucketOptions Options
113
113
114
114
using ( var binding = await GetSingleServerReadBindingAsync ( cancellationToken ) . ConfigureAwait ( false ) )
115
115
{
116
- var filesCollectionDocument = await GetFilesCollectionDocumentByNameAsync ( binding , filename , options . Revision , cancellationToken ) . ConfigureAwait ( false ) ;
117
- return await DownloadAsBytesHelperAsync ( binding , filesCollectionDocument , options , cancellationToken ) . ConfigureAwait ( false ) ;
116
+ var fileInfo = await GetFileInfoByNameAsync ( binding , filename , options . Revision , cancellationToken ) . ConfigureAwait ( false ) ;
117
+ return await DownloadAsBytesHelperAsync ( binding , fileInfo , options , cancellationToken ) . ConfigureAwait ( false ) ;
118
118
}
119
119
}
120
120
@@ -150,27 +150,27 @@ public ImmutableGridFSBucketOptions Options
150
150
151
151
using ( var binding = await GetSingleServerReadBindingAsync ( cancellationToken ) . ConfigureAwait ( false ) )
152
152
{
153
- var filesCollectionDocument = await GetFilesCollectionDocumentByNameAsync ( binding , filename , options . Revision , cancellationToken ) . ConfigureAwait ( false ) ;
154
- await DownloadToStreamHelperAsync ( binding , filesCollectionDocument , destination , options , cancellationToken ) . ConfigureAwait ( false ) ;
153
+ var fileInfo = await GetFileInfoByNameAsync ( binding , filename , options . Revision , cancellationToken ) . ConfigureAwait ( false ) ;
154
+ await DownloadToStreamHelperAsync ( binding , fileInfo , destination , options , cancellationToken ) . ConfigureAwait ( false ) ;
155
155
}
156
156
}
157
157
158
158
/// <inheritdoc />
159
- public async Task < IAsyncCursor < GridFSFilesCollectionDocument > > FindAsync ( FilterDefinition < GridFSFilesCollectionDocument > filter , GridFSFindOptions options = null , CancellationToken cancellationToken = default ( CancellationToken ) )
159
+ public async Task < IAsyncCursor < GridFSFileInfo > > FindAsync ( FilterDefinition < GridFSFileInfo > filter , GridFSFindOptions options = null , CancellationToken cancellationToken = default ( CancellationToken ) )
160
160
{
161
161
Ensure . IsNotNull ( filter , nameof ( filter ) ) ;
162
162
options = options ?? new GridFSFindOptions ( ) ;
163
163
164
164
var filesCollectionNamespace = GetFilesCollectionNamespace ( ) ;
165
165
var serializerRegistry = _database . Settings . SerializerRegistry ;
166
- var filesCollectionDocumentSerializer = serializerRegistry . GetSerializer < GridFSFilesCollectionDocument > ( ) ;
166
+ var fileInfoSerializer = serializerRegistry . GetSerializer < GridFSFileInfo > ( ) ;
167
167
var messageEncoderSettings = GetMessageEncoderSettings ( ) ;
168
- var renderedFilter = filter . Render ( filesCollectionDocumentSerializer , serializerRegistry ) ;
169
- var renderedSort = options . Sort == null ? null : options . Sort . Render ( filesCollectionDocumentSerializer , serializerRegistry ) ;
168
+ var renderedFilter = filter . Render ( fileInfoSerializer , serializerRegistry ) ;
169
+ var renderedSort = options . Sort == null ? null : options . Sort . Render ( fileInfoSerializer , serializerRegistry ) ;
170
170
171
- var operation = new FindOperation < GridFSFilesCollectionDocument > (
171
+ var operation = new FindOperation < GridFSFileInfo > (
172
172
filesCollectionNamespace ,
173
- filesCollectionDocumentSerializer ,
173
+ fileInfoSerializer ,
174
174
messageEncoderSettings )
175
175
{
176
176
BatchSize = options . BatchSize ,
@@ -216,8 +216,8 @@ public ImmutableGridFSBucketOptions Options
216
216
217
217
using ( var binding = await GetSingleServerReadBindingAsync ( cancellationToken ) . ConfigureAwait ( false ) )
218
218
{
219
- var filesCollectionDocument = await GetFilesCollectionDocumentByNameAsync ( binding , filename , options . Revision , cancellationToken ) . ConfigureAwait ( false ) ;
220
- return CreateDownloadStream ( binding . Fork ( ) , filesCollectionDocument , options ) ;
219
+ var fileInfo = await GetFileInfoByNameAsync ( binding , filename , options . Revision , cancellationToken ) . ConfigureAwait ( false ) ;
220
+ return CreateDownloadStream ( binding . Fork ( ) , fileInfo , options ) ;
221
221
}
222
222
}
223
223
@@ -345,7 +345,7 @@ private async Task CreateChunksCollectionIndexesAsync(IReadWriteBindingHandle bi
345
345
await operation . ExecuteAsync ( binding , cancellationToken ) . ConfigureAwait ( false ) ;
346
346
}
347
347
348
- private GridFSDownloadStream CreateDownloadStream ( IReadBindingHandle binding , GridFSFilesCollectionDocument filesCollectionDocument , GridFSDownloadOptions options = null , CancellationToken cancellationToken = default ( CancellationToken ) )
348
+ private GridFSDownloadStream CreateDownloadStream ( IReadBindingHandle binding , GridFSFileInfo fileInfo , GridFSDownloadOptions options = null , CancellationToken cancellationToken = default ( CancellationToken ) )
349
349
{
350
350
var checkMD5 = options . CheckMD5 ?? false ;
351
351
var seekable = options . Seekable ?? false ;
@@ -356,11 +356,11 @@ private async Task CreateChunksCollectionIndexesAsync(IReadWriteBindingHandle bi
356
356
357
357
if ( seekable )
358
358
{
359
- return new GridFSSeekableDownloadStream ( this , binding , filesCollectionDocument ) ;
359
+ return new GridFSSeekableDownloadStream ( this , binding , fileInfo ) ;
360
360
}
361
361
else
362
362
{
363
- return new GridFSForwardOnlyDownloadStream ( this , binding , filesCollectionDocument , checkMD5 ) ;
363
+ return new GridFSForwardOnlyDownloadStream ( this , binding , fileInfo , checkMD5 ) ;
364
364
}
365
365
}
366
366
@@ -406,33 +406,33 @@ private async Task CreateFilesCollectionIndexesAsync(IReadWriteBindingHandle bin
406
406
{
407
407
using ( var binding = await GetSingleServerReadBindingAsync ( cancellationToken ) . ConfigureAwait ( false ) )
408
408
{
409
- var filesCollectionDocument = await GetFilesCollectionDocumentAsync ( binding , id , cancellationToken ) . ConfigureAwait ( false ) ;
410
- return await DownloadAsBytesHelperAsync ( binding , filesCollectionDocument , options , cancellationToken ) . ConfigureAwait ( false ) ;
409
+ var fileInfo = await GetFileInfoAsync ( binding , id , cancellationToken ) . ConfigureAwait ( false ) ;
410
+ return await DownloadAsBytesHelperAsync ( binding , fileInfo , options , cancellationToken ) . ConfigureAwait ( false ) ;
411
411
}
412
412
}
413
413
414
- private async Task < byte [ ] > DownloadAsBytesHelperAsync ( IReadBindingHandle binding , GridFSFilesCollectionDocument filesCollectionDocument , GridFSDownloadOptions options , CancellationToken cancellationToken = default ( CancellationToken ) )
414
+ private async Task < byte [ ] > DownloadAsBytesHelperAsync ( IReadBindingHandle binding , GridFSFileInfo fileInfo , GridFSDownloadOptions options , CancellationToken cancellationToken = default ( CancellationToken ) )
415
415
{
416
- if ( filesCollectionDocument . Length > int . MaxValue )
416
+ if ( fileInfo . Length > int . MaxValue )
417
417
{
418
418
throw new NotSupportedException ( "GridFS stored file is too large to be returned as a byte array." ) ;
419
419
}
420
420
421
- using ( var destination = new MemoryStream ( ( int ) filesCollectionDocument . Length ) )
421
+ using ( var destination = new MemoryStream ( ( int ) fileInfo . Length ) )
422
422
{
423
- await DownloadToStreamHelperAsync ( binding , filesCollectionDocument , destination , options , cancellationToken ) . ConfigureAwait ( false ) ;
423
+ await DownloadToStreamHelperAsync ( binding , fileInfo , destination , options , cancellationToken ) . ConfigureAwait ( false ) ;
424
424
return destination . GetBuffer ( ) ;
425
425
}
426
426
}
427
427
428
- private async Task DownloadToStreamHelperAsync ( IReadBindingHandle binding , GridFSFilesCollectionDocument filesCollectionDocument , Stream destination , GridFSDownloadOptions options = null , CancellationToken cancellationToken = default ( CancellationToken ) )
428
+ private async Task DownloadToStreamHelperAsync ( IReadBindingHandle binding , GridFSFileInfo fileInfo , Stream destination , GridFSDownloadOptions options = null , CancellationToken cancellationToken = default ( CancellationToken ) )
429
429
{
430
430
var checkMD5 = options . CheckMD5 ?? false ;
431
431
432
- using ( var source = new GridFSForwardOnlyDownloadStream ( this , binding . Fork ( ) , filesCollectionDocument , checkMD5 ) )
432
+ using ( var source = new GridFSForwardOnlyDownloadStream ( this , binding . Fork ( ) , fileInfo , checkMD5 ) )
433
433
{
434
434
var count = source . Length ;
435
- var buffer = new byte [ filesCollectionDocument . ChunkSizeBytes ] ;
435
+ var buffer = new byte [ fileInfo . ChunkSizeBytes ] ;
436
436
437
437
while ( count > 0 )
438
438
{
@@ -450,8 +450,8 @@ private async Task CreateFilesCollectionIndexesAsync(IReadWriteBindingHandle bin
450
450
{
451
451
using ( var binding = await GetSingleServerReadBindingAsync ( cancellationToken ) . ConfigureAwait ( false ) )
452
452
{
453
- var filesCollectionDocument = await GetFilesCollectionDocumentAsync ( binding , id , cancellationToken ) . ConfigureAwait ( false ) ;
454
- await DownloadToStreamHelperAsync ( binding , filesCollectionDocument , destination , options , cancellationToken ) . ConfigureAwait ( false ) ;
453
+ var fileInfo = await GetFileInfoAsync ( binding , id , cancellationToken ) . ConfigureAwait ( false ) ;
454
+ await DownloadToStreamHelperAsync ( binding , fileInfo , destination , options , cancellationToken ) . ConfigureAwait ( false ) ;
455
455
}
456
456
}
457
457
@@ -476,17 +476,17 @@ internal CollectionNamespace GetChunksCollectionNamespace()
476
476
return new CollectionNamespace ( _database . DatabaseNamespace , _options . BucketName + ".chunks" ) ;
477
477
}
478
478
479
- private async Task < GridFSFilesCollectionDocument > GetFilesCollectionDocumentAsync ( IReadBindingHandle binding , BsonValue id , CancellationToken cancellationToken )
479
+ private async Task < GridFSFileInfo > GetFileInfoAsync ( IReadBindingHandle binding , BsonValue id , CancellationToken cancellationToken )
480
480
{
481
481
var filesCollectionNamespace = GetFilesCollectionNamespace ( ) ;
482
482
var serializerRegistry = _database . Settings . SerializerRegistry ;
483
- var filesCollectionDocumentSerializer = serializerRegistry . GetSerializer < GridFSFilesCollectionDocument > ( ) ;
483
+ var fileInfoSerializer = serializerRegistry . GetSerializer < GridFSFileInfo > ( ) ;
484
484
var messageEncoderSettings = GetMessageEncoderSettings ( ) ;
485
485
var filter = new BsonDocument ( "_id" , id ) ;
486
486
487
- var operation = new FindOperation < GridFSFilesCollectionDocument > (
487
+ var operation = new FindOperation < GridFSFileInfo > (
488
488
filesCollectionNamespace ,
489
- filesCollectionDocumentSerializer ,
489
+ fileInfoSerializer ,
490
490
messageEncoderSettings )
491
491
{
492
492
Filter = filter ,
@@ -495,30 +495,30 @@ private async Task<GridFSFilesCollectionDocument> GetFilesCollectionDocumentAsyn
495
495
496
496
using ( var cursor = await operation . ExecuteAsync ( binding , cancellationToken ) . ConfigureAwait ( false ) )
497
497
{
498
- var filesCollectionDocuments = await cursor . ToListAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
499
- var filesCollectionDocument = filesCollectionDocuments . FirstOrDefault ( ) ;
500
- if ( filesCollectionDocument == null )
498
+ var fileInfoList = await cursor . ToListAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
499
+ var fileInfo = fileInfoList . FirstOrDefault ( ) ;
500
+ if ( fileInfo == null )
501
501
{
502
502
throw new GridFSFileNotFoundException ( id ) ;
503
503
}
504
- return filesCollectionDocument ;
504
+ return fileInfo ;
505
505
}
506
506
}
507
507
508
- private async Task < GridFSFilesCollectionDocument > GetFilesCollectionDocumentByNameAsync ( IReadBindingHandle binding , string filename , int revision , CancellationToken cancellationToken )
508
+ private async Task < GridFSFileInfo > GetFileInfoByNameAsync ( IReadBindingHandle binding , string filename , int revision , CancellationToken cancellationToken )
509
509
{
510
510
var collectionNamespace = GetFilesCollectionNamespace ( ) ;
511
511
var serializerRegistry = _database . Settings . SerializerRegistry ;
512
- var filesCollectionDocumentSerializer = serializerRegistry . GetSerializer < GridFSFilesCollectionDocument > ( ) ;
512
+ var fileInfoSerializer = serializerRegistry . GetSerializer < GridFSFileInfo > ( ) ;
513
513
var messageEncoderSettings = GetMessageEncoderSettings ( ) ;
514
514
var filter = new BsonDocument ( "filename" , filename ) ;
515
515
var skip = revision >= 0 ? revision : - revision - 1 ;
516
516
var limit = 1 ;
517
517
var sort = new BsonDocument ( "uploadDate" , revision >= 0 ? 1 : - 1 ) ;
518
518
519
- var operation = new FindOperation < GridFSFilesCollectionDocument > (
519
+ var operation = new FindOperation < GridFSFileInfo > (
520
520
collectionNamespace ,
521
- filesCollectionDocumentSerializer ,
521
+ fileInfoSerializer ,
522
522
messageEncoderSettings )
523
523
{
524
524
Filter = filter ,
@@ -529,13 +529,13 @@ private async Task<GridFSFilesCollectionDocument> GetFilesCollectionDocumentByNa
529
529
530
530
using ( var cursor = await operation . ExecuteAsync ( binding , cancellationToken ) . ConfigureAwait ( false ) )
531
531
{
532
- var filesCollectionDocuments = await cursor . ToListAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
533
- var filesCollectionDocument = filesCollectionDocuments . FirstOrDefault ( ) ;
534
- if ( filesCollectionDocument == null )
532
+ var fileInfoList = await cursor . ToListAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
533
+ var fileInfo = fileInfoList . FirstOrDefault ( ) ;
534
+ if ( fileInfo == null )
535
535
{
536
536
throw new GridFSFileNotFoundException ( filename , revision ) ;
537
537
}
538
- return filesCollectionDocument ;
538
+ return fileInfo ;
539
539
}
540
540
}
541
541
@@ -602,8 +602,8 @@ private async Task<bool> IsFilesCollectionEmptyAsync(IReadWriteBindingHandle bin
602
602
603
603
using ( var binding = await GetSingleServerReadBindingAsync ( cancellationToken ) . ConfigureAwait ( false ) )
604
604
{
605
- var filesCollectionDocument = await GetFilesCollectionDocumentAsync ( binding , id , cancellationToken ) . ConfigureAwait ( false ) ;
606
- return CreateDownloadStream ( binding . Fork ( ) , filesCollectionDocument , options , cancellationToken ) ;
605
+ var fileInfo = await GetFileInfoAsync ( binding , id , cancellationToken ) . ConfigureAwait ( false ) ;
606
+ return CreateDownloadStream ( binding . Fork ( ) , fileInfo , options , cancellationToken ) ;
607
607
}
608
608
}
609
609
0 commit comments