mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
28 changed files with 244 additions and 164 deletions
@ -1,35 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL; |
|||
using GraphQL.NewtonsoftJson; |
|||
using Microsoft.AspNetCore.WebUtilities; |
|||
using Newtonsoft.Json; |
|||
|
|||
namespace Squidex.Web.GraphQL |
|||
{ |
|||
public sealed class BufferingDocumentWriter : IDocumentWriter |
|||
{ |
|||
private readonly DocumentWriter documentWriter; |
|||
|
|||
public BufferingDocumentWriter(Action<JsonSerializerSettings> action) |
|||
{ |
|||
documentWriter = new DocumentWriter(action); |
|||
} |
|||
|
|||
public async Task WriteAsync<T>(Stream stream, T value, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await using (var bufferStream = new FileBufferingWriteStream()) |
|||
{ |
|||
await documentWriter.WriteAsync(bufferStream, value, cancellationToken); |
|||
|
|||
await bufferStream.DrainBufferAsync(stream, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL; |
|||
using Microsoft.AspNetCore.WebUtilities; |
|||
|
|||
namespace Squidex.Web.GraphQL |
|||
{ |
|||
public sealed class BufferingGraphQLSerializer : IGraphQLTextSerializer |
|||
{ |
|||
private readonly IGraphQLTextSerializer inner; |
|||
|
|||
public BufferingGraphQLSerializer(IGraphQLTextSerializer inner) |
|||
{ |
|||
this.inner = inner; |
|||
} |
|||
|
|||
public async ValueTask<T?> ReadAsync<T>(Stream stream, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await using (var bufferStream = new FileBufferingReadStream(stream, 30 * 1024)) |
|||
{ |
|||
await bufferStream.DrainAsync(cancellationToken); |
|||
|
|||
bufferStream.Seek(0L, SeekOrigin.Begin); |
|||
|
|||
return await inner.ReadAsync<T>(bufferStream, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task WriteAsync<T>(Stream stream, T? value, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await using (var bufferStream = new FileBufferingWriteStream()) |
|||
{ |
|||
await inner.WriteAsync(bufferStream, value, cancellationToken); |
|||
|
|||
await bufferStream.DrainBufferAsync(stream, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public string Serialize<T>(T? value) |
|||
{ |
|||
return inner.Serialize<T>(value); |
|||
} |
|||
|
|||
public T? Deserialize<T>(string? value) |
|||
{ |
|||
return inner.Deserialize<T>(value); |
|||
} |
|||
|
|||
public T? ReadNode<T>(object? value) |
|||
{ |
|||
return inner.ReadNode<T>(value); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue