DeltaZip.ArchiveWriter.FlushBuffer C# (CSharp) Method

FlushBuffer() public method

public FlushBuffer ( bool final ) : void
final bool
return void
        void FlushBuffer(bool final)
        {
            if (WriteBuffer.Length > 0) {
                // Name the entry
                string nameWithSuffix = (final && BufferNameSuffix == 0 && !BufferNameForceAppendSuffix) ? BufferName : (BufferName + "~" + BufferNameSuffix.ToString("D3"));
                BufferNameSuffix++;

                // Patch hashes
                foreach (int hashIndex in HashIndexesForPatching) {
                    HashSource copy = hashes[hashIndex];
                    copy.Path = AddString(@"\" + nameWithSuffix);
                    hashes[hashIndex] = copy;
                }
                HashIndexesForPatching.Clear();

                // Content of entity
                MemoryStream entityContent = this.WriteBuffer;

                // Allocate new tmp stream
                this.WriteBuffer = StreamPool.Allocate();

                MethodInvoker writeMethod = delegate {
                    bool compress = entityContent.Length > Settings.CompressionMinSize && Util.IsCompressable(entityContent);
                    long oldCompressedSize = baseStream.Position;

                    zipStream.ParallelDeflateThreshold = entityContent.Length >= Settings.MinSizeForParallelDeflate ? 0 /* on */ : -1 /* off */;
                    ZipEntry entry = zipStream.PutNextEntry(nameWithSuffix);
                    entry.CompressionLevel = compress ? (CompressionLevel)Settings.CompressionLevel : CompressionLevel.None;
                    entityContent.Position = 0;
                    entityContent.WriteTo(zipStream);
                    zipStream.Flush();

                    long compressedSize = baseStream.Position - oldCompressedSize;
                    stats.Compressed += compressedSize;
                    stats.SavedByCompression += entityContent.Length - compressedSize;

                    StreamPool.Release(ref entityContent);
                };

                workerThread.Enqueue(writeMethod);
            }
        }