mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 22:17:22 +01:00
custom file stream implementation
This commit is contained in:
parent
a3b33c0e6b
commit
56b27e5ee8
5 changed files with 153 additions and 17 deletions
|
|
@ -2,8 +2,6 @@
|
|||
using MareSynchronosStaticFilesServer.Services;
|
||||
using MareSynchronosStaticFilesServer.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronosStaticFilesServer.Controllers;
|
||||
|
||||
|
|
@ -34,27 +32,22 @@ public class CacheController : ControllerBase
|
|||
_requestQueue.ActivateRequest(requestId);
|
||||
|
||||
Response.ContentType = "application/octet-stream";
|
||||
var memoryStream = new MemoryStream();
|
||||
var streamWriter = new BinaryWriter(memoryStream);
|
||||
|
||||
long requestSize = 0;
|
||||
List<BlockFileDataSubstream> substreams = new();
|
||||
|
||||
foreach (var file in request.FileIds)
|
||||
{
|
||||
var fs = await _cachedFileProvider.GetAndDownloadFileStream(file);
|
||||
if (fs == null) continue;
|
||||
streamWriter.Write(Encoding.ASCII.GetBytes("#" + file + ":" + fs.Length.ToString(CultureInfo.InvariantCulture) + "#"));
|
||||
byte[] buffer = new byte[fs.Length];
|
||||
_ = await fs.ReadAsync(buffer, HttpContext.RequestAborted);
|
||||
streamWriter.Write(buffer);
|
||||
|
||||
substreams.Add(new(fs));
|
||||
|
||||
requestSize += fs.Length;
|
||||
}
|
||||
|
||||
streamWriter.Flush();
|
||||
memoryStream.Position = 0;
|
||||
|
||||
_fileStatisticsService.LogRequest(requestSize);
|
||||
|
||||
return _requestFileStreamResultFactory.Create(requestId, memoryStream);
|
||||
return _requestFileStreamResultFactory.Create(requestId, new BlockFileDataStream(substreams.ToArray()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue