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);
        }
Esempio n. 2
0
        private async Task <Chunk <TBody> > ReadDataChunkAsync <TBody>(
            Stream imageReaderStream,
            ChunkLayout chunkLayout,
            StructureType type,
            Serializer <TBody> serializer,
            int index,
            string invalidChunkMessage) where TBody : class
        {
            var chunkInfo = chunkLayout.OrderedChunkInfo.ElementAt(index);

            if (chunkInfo.Type != type)
            {
                throw new InvalidFormatException(invalidChunkMessage);
            }

            return(await _chunkReader.ReadChunkAsync(imageReaderStream, chunkInfo, serializer));
        }