I receive request to receive file content from WebApi.
The request can also contain range
header and so for that I use ByteRangeStreamContent
to generate the content and then finally send this content as HttpResponse
.
This is the code that I use
var contentType = new MediaTypeHeaderValue("application/octet-stream");
var bytes = fileProvider.GetFile(fileId);
var stream = new MemoryStream(bytes);
if (Request.Headers.Range != null)
{
var content = new ByteRangeStreamContent(stream, Request.Headers.Range, contentType);
return ByteArrayHttpResponseMessage(content);
}
else
{
var content = new ByteArrayContent(stream.ToArray());
return ByteArrayHttpResponseMessage(content);
}
I have to add CRC32 check with the data now.
This I can do easily when the range header is not sent, because then I have access the byte array which I can use to calculate and add CRC32.
The problem arises when the range variable is sent, because then I don't have access to the actual data in byte array form that is being sent, I only have ByteRangeStreamContent
and so I cannot update it with CRC32 before sending.
I checked that it does have the method ReadAsByteArrayAsync()
, but I don't know if it is the right way to extract array from ByteRangeStreamContent
then add CRC32 to the array then again try to generate updated ByteRangeStreamContent
object.
Is there any way to do this?