You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// then data will be read from M-Files in blocks of this size.
50
+
/// </summary>
51
+
publicconstintMaximumBlockSize=4*1024*1024;
52
+
45
53
/// <summary>
46
54
/// Creates a <see cref="FileDownloadStream"/> but does not open the download session.
47
55
/// </summary>
@@ -168,27 +176,47 @@ public override int Read(byte[] buffer, int offset, int count)
168
176
if(this.Position>=this.DownloadSession.FileSize)
169
177
return0;
170
178
171
-
// Read the block.
172
-
varblockData=this
173
-
.Vault
174
-
.ObjectFileOperations
175
-
.DownloadFileInBlocks_ReadBlock
176
-
(
177
-
this.DownloadSession.DownloadID,
178
-
count,
179
-
this.position
180
-
);
179
+
// Loop through and get max 4MB blocks.
180
+
intdataRead=0;
181
+
boolatEnd=false;
182
+
while(dataRead<count&&!atEnd)
183
+
{
184
+
// Work out how much to get.
185
+
varblockSize=count;
186
+
if(blockSize>MaximumBlockSize)
187
+
blockSize=MaximumBlockSize;
188
+
if(dataRead+blockSize>this.Length)
189
+
blockSize=(int)(this.Length-dataRead);
190
+
if(blockSize<=0)
191
+
break;
192
+
193
+
// Read the block.
194
+
varblockData=this
195
+
.Vault
196
+
.ObjectFileOperations
197
+
.DownloadFileInBlocks_ReadBlock
198
+
(
199
+
this.DownloadSession.DownloadID,
200
+
blockSize,
201
+
this.position
202
+
);
203
+
204
+
// Check the buffer is big enough.
205
+
if(dataRead+blockData.Length>buffer.Length)
206
+
thrownewArgumentException($"The buffer size ({buffer.Length}) is not big enough to hold the amount of data requested ({dataRead+blockData.Length}).",nameof(buffer));
181
207
182
-
// Check the buffer is big enough.
183
-
if(blockData.Length>buffer.Length)
184
-
thrownewArgumentException($"The buffer size ({buffer.Length}) is not big enough to hold the amount of data requested ({count}).",nameof(buffer));
0 commit comments