Ejemplo n.º 1
0
 private IEnumerable<Chunk> PrepareChunks()
 {
     var chunks = new List<Chunk>();
     var n = (int)(batchPosition / chunkSizeBytes);
     foreach( var chunk in batch )
     {
         var c = new Chunk
             {
                 FileId = filesInfoId,
                 Num = n++,
                 Data = chunk
             };
         chunks.Add(c);
         batchPosition += chunk.Length;
         sha256.AppendData(chunk);
     }
     return chunks;
 }
        private byte[] GetChunkHelper(long n, Chunk doc)
        {
            var data = doc.Data;

            var chunkSizeBytes = FileInfo.ChunkSizeBytes;
            var lastChunk = FileInfo.Length / FileInfo.ChunkSizeBytes;
            var expectedChunkSize = n == lastChunk ? FileInfo.Length % chunkSizeBytes : chunkSizeBytes;
            if( data.Length != expectedChunkSize )
            {
                throw new ChunkException(FileInfo.Id, n, "the wrong size");
            }

            return data;
        }