Skip to content

Commit d05ea1c

Browse files
committed
stream input
1 parent 055f5f7 commit d05ea1c

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

App.razor

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,16 @@
270270
try
271271
{
272272
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))
277277
{
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);
285279
}
280+
var outputBytes = outputStream.ToArray();
281+
file.OutputSize = outputBytes.Length;
282+
await BlazorDownloadFileService.DownloadFile(file.NewName, outputBytes, "application/octet-stream");
286283

287284
file.Status = "Finished";
288285
}
@@ -312,20 +309,16 @@
312309
try
313310
{
314311
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))
320316
{
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);
328318
}
319+
var outputBytes = outputStream.ToArray();
320+
file.OutputSize = outputBytes.Length;
321+
await BlazorDownloadFileService.DownloadFile(file.NewName, outputBytes, "application/octet-stream");
329322

330323
file.Status = "Finished";
331324
}

e2e/tests/app.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test('compress button is disabled with no files selected', async ({ page }) => {
3434
});
3535

3636
test('compression level options are hidden in decompress mode', async ({ page }) => {
37-
await page.locator('#radio-decompress').check();
37+
await page.locator('label[for="radio-decompress"]').click();
3838
await expect(page.locator('#radio-optimal')).not.toBeVisible();
3939
await expect(page.getByRole('button', { name: 'Decompress Files' })).toBeDisabled();
4040
});
@@ -67,7 +67,7 @@ test('decompress a file end-to-end', async ({ page }) => {
6767
fs.writeFileSync(srcFile, 'Hello, GZIP decompressed!');
6868
execSync(`gzip -kf ${srcFile}`);
6969

70-
await page.locator('#radio-decompress').check();
70+
await page.locator('label[for="radio-decompress"]').click();
7171

7272
const downloadPromise = page.waitForEvent('download');
7373
await page.locator('input[type="file"]').setInputFiles(gzFile);

0 commit comments

Comments
 (0)