Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I was having an issue with an even smaller size (400kb ish) #33

Open
arivera12 opened this issue Dec 16, 2021 · 3 comments
Open

I was having an issue with an even smaller size (400kb ish) #33

arivera12 opened this issue Dec 16, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@arivera12
Copy link
Owner

I was having an issue with an even smaller size (400kb ish)

I turned my stream into a byte array and it worked.

@arivera12, you might want to impliment this

byte[] myByteArray;
using (var memoryStream = new MemoryStream())
{
    originalStream.CopyTo(memoryStream);
    myByteArray= memoryStream.ToArray();
}

for your

internal static async Task<byte[]> ToByteArrayAsync(this Stream stream)
{
    var streamLength = (int)stream.Length;
    var data = new byte[streamLength];
    stream.Position = 0;
    await stream.ReadAsync(data, 0, streamLength);
    return data;
}

I can submit a PR if you need/like

Originally posted by @thalaeg in #25 (comment)

@arivera12
Copy link
Owner Author

@thalaeg can you compare the bytes length of the .xlsx file when using the stream and byte[] overload methods?

@thalaeg
Copy link

thalaeg commented Dec 16, 2021

sure. Interestly, something I discovered by accident,

await BlazorDownloadFileService.DownloadFile("streamFile.xlsx", myStream, CancellationToken.None, CancellationToken.None, progress: null);
does not work.

but
await BlazorDownloadFileService.DownloadFile("streamFile.xlsx", myStream, contentType: "application/octet-stream");

seems to work.

Byte size: 373,633
Stream size (failing): 163,840
Stream size (Working): 373,633

@arivera12 arivera12 self-assigned this Dec 19, 2021
@arivera12 arivera12 added the bug Something isn't working label Dec 19, 2021
@arivera12
Copy link
Owner Author

@thalaeg

The method that works have a different implementation from the one that **doesn't work.

The buffered method that is the one that doesn't work I may be having issues reading the bytes from the stream.

public async ValueTask<DownloadFileResult> DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, CancellationToken cancellationTokenJavaScriptInterop, int bufferSize = 32768, string contentType = "application/octet-stream", IProgress<double>? progress = null)

163,840 bytes is almost half size 373,633 / 2 = 186,816.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants