Description
In my application, I need to support downloading arbitrary chunks of a GridFS file per request. To do this, I'm using bucket.OpenDownloadStream (setting Seekable to True in the options), and Stream.Read.
I get a NullReferenceException in GridFSSeekableDownloadStream.GetSegment at:
var segmentCount = _chunk.Length - segmentOffset;
|
because _chunk is null.
Here is a test that can be added to GridFSDownloadStreamBaseTests
[Test]
|
public void Read_should_not_throw(
|
[Values(0.5, 1.0, 1.5, 2.0, 2.5)] double contentSizeMultiple,
|
[Values(false, true)] bool async,
|
[Values(false, true)] bool seekable)
|
{
|
var bucket = CreateBucket(128);
|
var contentSize = (int)(bucket.Options.ChunkSizeBytes * contentSizeMultiple);
|
var content = CreateContent(contentSize);
|
var id = CreateGridFSFile(bucket, content);
|
var options = new GridFSDownloadOptions() {Seekable = seekable };
|
var subject = bucket.OpenDownloadStream(id, options);
|
|
|
var buffer = new byte[contentSize];
|
|
|
if (async)
|
{
|
subject.ReadAsync(buffer, 0, contentSize).GetAwaiter().GetResult();
|
}
|
else
|
{
|
subject.Read(buffer, 0, contentSize);
|
}
|
}
|