Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.3 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using GraphQL;
using Microsoft.AspNetCore.WebUtilities;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Json;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
{
public sealed class DefaultDocumentWriter : IDocumentWriter
{
private readonly IJsonSerializer jsonSerializer;
public DefaultDocumentWriter(IJsonSerializer jsonSerializer)
{
Guard.NotNull(jsonSerializer, nameof(jsonSerializer));
this.jsonSerializer = jsonSerializer;
}
public async Task WriteAsync<T>(Stream stream, T value, CancellationToken cancellationToken = default)
{
await using (var buffer = new FileBufferingWriteStream())
{
jsonSerializer.Serialize(value, buffer, true);
await buffer.DrainBufferAsync(stream, cancellationToken);
}
}
}
}