mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 19:27:21 +01:00
help?
This commit is contained in:
parent
ff81b269b8
commit
e7b72baa1e
4 changed files with 7 additions and 6 deletions
|
|
@ -48,6 +48,6 @@ public class CacheController : ControllerBase
|
|||
|
||||
_fileStatisticsService.LogRequest(requestSize);
|
||||
|
||||
return _requestFileStreamResultFactory.Create(requestId, new BlockFileDataStream(substreams.ToArray()));
|
||||
return _requestFileStreamResultFactory.Create(requestId, new BlockFileDataStream(substreams));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
public sealed class BlockFileDataStream : Stream
|
||||
{
|
||||
private readonly BlockFileDataSubstream[] _substreams;
|
||||
private readonly List<BlockFileDataSubstream> _substreams;
|
||||
private int _currentStreamIndex = 0;
|
||||
|
||||
public BlockFileDataStream(BlockFileDataSubstream[] substreams)
|
||||
public BlockFileDataStream(List<BlockFileDataSubstream> substreams)
|
||||
{
|
||||
_substreams = substreams;
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public sealed class BlockFileDataStream : Stream
|
|||
int totalRead = 0;
|
||||
int currentOffset = 0;
|
||||
int remainingCount = count;
|
||||
while (totalRead < count && _currentStreamIndex < _substreams.Length)
|
||||
while (totalRead < count && _currentStreamIndex < _substreams.Count)
|
||||
{
|
||||
var lastReadBytes = _substreams[_currentStreamIndex].Read(buffer, currentOffset, remainingCount);
|
||||
if (lastReadBytes < remainingCount)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public sealed class BlockFileDataSubstream : IDisposable
|
|||
public BlockFileDataSubstream(FileStream dataStream)
|
||||
{
|
||||
_headerStream = new MemoryStream();
|
||||
var headerStreamWriter = new BinaryWriter(_headerStream);
|
||||
using var headerStreamWriter = new BinaryWriter(_headerStream);
|
||||
headerStreamWriter.Write(Encoding.ASCII.GetBytes("#" + new FileInfo(dataStream.Name).Name + ":" + dataStream.Length.ToString(CultureInfo.InvariantCulture) + "#"));
|
||||
headerStreamWriter.Flush();
|
||||
_headerStream.Position = 0;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class RequestFileStreamResult : FileStreamResult
|
|||
_requestQueueService.FinishRequest(_requestId);
|
||||
|
||||
_mareMetrics.DecGauge(MetricsAPI.GaugeCurrentDownloads);
|
||||
FileStream?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,8 +51,8 @@ public class RequestFileStreamResult : FileStreamResult
|
|||
finally
|
||||
{
|
||||
_requestQueueService.FinishRequest(_requestId);
|
||||
|
||||
_mareMetrics.DecGauge(MetricsAPI.GaugeCurrentDownloads);
|
||||
FileStream?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue