|
270 | 270 | try |
271 | 271 | { |
272 | 272 | var browserFile = file.BrowserFile; |
273 | | - var buffer = new byte[browserFile.Size]; |
274 | | - await browserFile.OpenReadStream(long.MaxValue).ReadAsync(buffer); |
275 | | - file.OriginalSize = buffer.Length; |
276 | | - using (var outputStream = new MemoryStream()) |
| 273 | + file.OriginalSize = browserFile.Size; |
| 274 | + using var inputStream = browserFile.OpenReadStream(long.MaxValue); |
| 275 | + using var outputStream = new MemoryStream(); |
| 276 | + using (var compressionStream = CreateCompressStream(outputStream, compressionLevel)) |
277 | 277 | { |
278 | | - using (var compressionStream = CreateCompressStream(outputStream, compressionLevel)) |
279 | | - { |
280 | | - await compressionStream.WriteAsync(buffer, 0, buffer.Length); |
281 | | - } |
282 | | - var outputBytes = outputStream.ToArray(); |
283 | | - file.OutputSize = outputBytes.Length; |
284 | | - await BlazorDownloadFileService.DownloadFile(file.NewName, outputBytes, "application/octet-stream"); |
| 278 | + await inputStream.CopyToAsync(compressionStream); |
285 | 279 | } |
| 280 | + var outputBytes = outputStream.ToArray(); |
| 281 | + file.OutputSize = outputBytes.Length; |
| 282 | + await BlazorDownloadFileService.DownloadFile(file.NewName, outputBytes, "application/octet-stream"); |
286 | 283 |
|
287 | 284 | file.Status = "Finished"; |
288 | 285 | } |
|
312 | 309 | try |
313 | 310 | { |
314 | 311 | var browserFile = file.BrowserFile; |
315 | | - var buffer = new byte[browserFile.Size]; |
316 | | - await browserFile.OpenReadStream(long.MaxValue).ReadAsync(buffer); |
317 | | - file.OriginalSize = buffer.Length; |
318 | | - using (var inputStream = new MemoryStream(buffer)) |
319 | | - using (var outputStream = new MemoryStream()) |
| 312 | + file.OriginalSize = browserFile.Size; |
| 313 | + using var inputStream = browserFile.OpenReadStream(long.MaxValue); |
| 314 | + using var outputStream = new MemoryStream(); |
| 315 | + using (var decompressionStream = CreateDecompressStream(inputStream)) |
320 | 316 | { |
321 | | - using (var compressionStream = CreateDecompressStream(inputStream)) |
322 | | - { |
323 | | - await compressionStream.CopyToAsync(outputStream); |
324 | | - } |
325 | | - var outputBytes = outputStream.ToArray(); |
326 | | - file.OutputSize = outputBytes.Length; |
327 | | - await BlazorDownloadFileService.DownloadFile(file.NewName, outputBytes, "application/octet-stream"); |
| 317 | + await decompressionStream.CopyToAsync(outputStream); |
328 | 318 | } |
| 319 | + var outputBytes = outputStream.ToArray(); |
| 320 | + file.OutputSize = outputBytes.Length; |
| 321 | + await BlazorDownloadFileService.DownloadFile(file.NewName, outputBytes, "application/octet-stream"); |
329 | 322 |
|
330 | 323 | file.Status = "Finished"; |
331 | 324 | } |
|
0 commit comments