public IImageDecoder BuildDecoder(Stream imageReaderStream, DecodingConfiguration decodingConfiguration) { Header header; try { header = new HeaderSerializer(Signature.Bytes.Length).DeserializeAsync(imageReaderStream).Result; } catch (Exception) { throw new InvalidHeaderException("Could not read file header"); } if (!header.Signature.SequenceEqual(Signature.Bytes)) { throw new InvalidHeaderException("Incorrect file signature"); } if (!Enum.IsDefined(typeof(Version), header.Version)) { throw new UnsupportedVersionException(String.Format("File with version {0} is not supported", header.Version)); } switch ((Version)header.Version) { case Version.V1: return(new V1.ImageDecoder(decodingConfiguration)); case Version.V2: return(new V2.ImageDecoder(decodingConfiguration)); default: throw new UnsupportedVersionException(String.Format("File with version {0} is not supported", header.Version)); } }
public async Task WriteThenRead_ProducesEquivalentOutput(ChunkConfiguration chunkConfig, TBody body) { var orignalChunk = new Chunk <TBody>(chunkConfig, body); var storageStream = new MemoryStream(); Serializer <TBody> chunkBodySerializer = GetBodySerializer(orignalChunk); var encodingConfiguration = new EncodingConfiguration("somePass!!", new MemoryStorageProvider(), 4096, 1024 * 1000); var decodingConfiguration = new DecodingConfiguration("somePass!!", new MemoryStorageProvider(), 4096); ChunkWriter writer = GetChunkWriter(encodingConfiguration); await writer.WriteChunkAsync(storageStream, chunkBodySerializer, orignalChunk); if (storageStream.Length == 0) { Debugger.Break(); } storageStream.Position = 0; ChunkReader reader = GetChunkReader(decodingConfiguration); Chunk <TBody> decodedChunk = await reader.ReadChunkAsync(storageStream, new ChunkInfo(chunkConfig, storageStream.Length), chunkBodySerializer); AssertEqual(orignalChunk, decodedChunk); }
public ChunkReader( DecodingConfiguration configuration, CompressionFactory compressionFactory, EncryptionFactory encryptionFactory) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (compressionFactory == null) { throw new ArgumentNullException("compressionFactory"); } if (encryptionFactory == null) { throw new ArgumentNullException("encryptionFactory"); } _configuration = configuration; _compressionFactory = compressionFactory; _encryptionFactory = encryptionFactory; }
public static async Task <ImageDecoder> LoadAsync(Stream imageStream, DecodingConfiguration decodingConfiguration) { var decoder = new ImageDecoder(); if (imageStream == null) { throw new ArgumentNullException("imageStream"); } if (decodingConfiguration == null) { throw new ArgumentNullException("decodingConfiguration"); } decoder._rawStream = imageStream; decoder._originalPosition = imageStream.Position; decoder._decodingConfiguration = decodingConfiguration; decoder._imageFormat = new ImageFormatFactory().GetFormatFromStream(imageStream); await decoder.LoadDecoderAsync(); decoder._dataInfo = await decoder._imageDecoder.ReadDataInfoAsync(decoder._imageReaderStream); return(decoder); }
public ChunkReader(DecodingConfiguration configuration) : this( configuration, new CompressionFactory(), new EncryptionFactory()) { }
public ImageDecoder(DecodingConfiguration decodingConfiguration) : base(decodingConfiguration) { _chunkReader = new ChunkReader(decodingConfiguration); }
protected ImageDecoderBase(DecodingConfiguration decodingConfiguration) { _decodingConfiguration = decodingConfiguration; }
internal virtual ChunkReader GetChunkReader(DecodingConfiguration configuration) { return(new ChunkReader(configuration)); }