// Copyright 2017-2018 Alexander Luzgarev using System.IO; namespace MatFileHandler.Tests { /// /// A method of writing an IMatFile into a stream that is not seekable. /// public class MatFileWritingToUnseekableStream : MatFileWritingMethod { private readonly MatFileWriterOptions? _maybeOptions; /// /// Initializes a new instance of the class. /// /// Options for the . public MatFileWritingToUnseekableStream(MatFileWriterOptions? maybeOptions) { _maybeOptions = maybeOptions; } /// public override byte[] WriteMatFile(IMatFile matFile) { using var memoryStream = new MemoryStream(); using var unseekableStream = new UnseekableWriteStream(memoryStream); var matFileWriter = _maybeOptions switch { { } options => new MatFileWriter(unseekableStream, options), _ => new MatFileWriter(unseekableStream), }; matFileWriter.Write(matFile); return memoryStream.ToArray(); } } }