inner-pipe
This commit is contained in:
parent
c92383721d
commit
8b10c3b27e
1 changed files with 23 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System.Buffers;
|
||||
using System.IO.Pipelines;
|
||||
using Microsoft.AspNetCore.Http.Json;
|
||||
using NetVips;
|
||||
|
|
@ -34,7 +35,28 @@ app.MapPost("/api/image/generate", (Stitch request) =>
|
|||
try
|
||||
{
|
||||
using Image image = Tile.Create(in request, tilesDirectory, images, logger);
|
||||
image.WriteToStream(pipe.Writer.AsStream(), ".png");
|
||||
Pipe innerPipe = new();
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
ReadResult result = await innerPipe.Reader.ReadAsync();
|
||||
ReadOnlySequence<byte> buffer = result.Buffer;
|
||||
if(!buffer.IsEmpty )
|
||||
{
|
||||
foreach( ReadOnlyMemory<byte> segment in buffer )
|
||||
{
|
||||
await pipe.Writer.WriteAsync(segment);
|
||||
}
|
||||
innerPipe.Reader.AdvanceTo(buffer.End);
|
||||
if (result.IsCompleted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
image.WriteToStream(innerPipe.Writer.AsStream(), ".png");
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue