Пример #1
0
        //Main decompress multi-thread logic
        private static void InteralDecompressOperation(FileInfo sourceFile, FileStream originalFileStream, CompressionMode compressionMode)
        {
            ThreadFactory threadFactory    = new ThreadFactory(WriteDataToMemoryStream);
            int           readedBytesCount = 0;
            var           chunkInfos       = sourceFile.GetChunksOfGZip(BlockSize);

            foreach (var chunkInfo in chunkInfos)
            {
                int    chunkNumber = chunkInfo.Key;
                int    chunkLength = chunkInfo.Value;
                byte[] buffer      = new byte[chunkLength];

                if ((readedBytesCount = originalFileStream.Read(buffer, 0, chunkLength)) > 0)
                {
                    threadFactory.CreateNew().Start(new WriteToStreamInfo
                    {
                        Number          = chunkNumber,
                        Buffer          = (byte[])buffer.Clone(),
                        BytesCount      = readedBytesCount,
                        CompressionMode = compressionMode
                    });
                }
            }
            while (threadFactory.IsAlive)
            {
            }
        }
Пример #2
0
        //Main compress multi-thread logic
        private static void InternalCompressOperation(FileStream originalFileStream, CompressionMode compressionMode)
        {
            ThreadFactory threadFactory = new ThreadFactory(WriteDataToMemoryStream);

            byte[] buffer           = new byte[BlockSize];
            int    readedBytesCount = 0;
            int    number           = 0;

            while ((readedBytesCount = originalFileStream.Read(buffer, 0, BlockSize)) > 0)
            {
                threadFactory.CreateNew().Start(new WriteToStreamInfo
                {
                    Number          = ++number,
                    Buffer          = (byte[])buffer.Clone(),
                    BytesCount      = readedBytesCount,
                    CompressionMode = compressionMode
                });
            }
            while (threadFactory.IsAlive)
            {
            }
        }