public void FlushBlock(byte[] stored, int storedOffset, int storedLength, bool lastBlock)
{
this.literalTree.freqs[0x100] = (short) (this.literalTree.freqs[0x100] + 1);
this.literalTree.BuildTree();
this.distTree.BuildTree();
this.literalTree.CalcBLFreq(this.blTree);
this.distTree.CalcBLFreq(this.blTree);
this.blTree.BuildTree();
int blTreeCodes = 4;
for (int i = 0x12; i > blTreeCodes; i--)
{
if (this.blTree.length[BL_ORDER[i]] > 0)
{
blTreeCodes = i + 1;
}
}
int num3 = ((((14 + (blTreeCodes * 3)) + this.blTree.GetEncodedLength()) + this.literalTree.GetEncodedLength()) + this.distTree.GetEncodedLength()) + this.extra_bits;
int num4 = this.extra_bits;
for (int j = 0; j < 0x11e; j++)
{
num4 += this.literalTree.freqs[j] * staticLLength[j];
}
for (int k = 0; k < 30; k++)
{
num4 += this.distTree.freqs[k] * staticDLength[k];
}
if (num3 >= num4)
{
num3 = num4;
}
if ((storedOffset >= 0) && ((storedLength + 4) < (num3 >> 3)))
{
this.FlushStoredBlock(stored, storedOffset, storedLength, lastBlock);
}
else if (num3 == num4)
{
this.pending.WriteBits(2 + (lastBlock ? 1 : 0), 3);
this.literalTree.SetStaticCodes(staticLCodes, staticLLength);
this.distTree.SetStaticCodes(staticDCodes, staticDLength);
this.CompressBlock();
this.Init();
}
else
{
this.pending.WriteBits(4 + (lastBlock ? 1 : 0), 3);
this.SendAllTrees(blTreeCodes);
this.CompressBlock();
this.Init();
}
}