Bio.IO.BAM.BAMFormatter.GetBGZFStructure C# (CSharp) Method

GetBGZFStructure() private static method

Gets BGZF structure from the GZipStream compression.
private static GetBGZFStructure ( Stream compressedStream ) : byte[]
compressedStream Stream BAM file which is compressed according to BGZF compression.
return byte[]
        private static byte[] GetBGZFStructure(Stream compressedStream)
        {
            byte[] compressedArray = new byte[compressedStream.Length];
            compressedStream.Read(compressedArray, 0, (int)compressedStream.Length);
            UInt16 blockSize = (UInt16)(compressedStream.Length + 8);
            byte[] bgzfArray = new byte[blockSize];

            bgzfArray[0] = 31;  // gzip IDentifier1
            bgzfArray[1] = 139; // gzip IDentifier2
            bgzfArray[2] = 8;   // gzip Compression Method 
            bgzfArray[3] = 4;   // gzip FLaGs
            bgzfArray[9] = 255; // gzip Operating System "255 - unknown"
            bgzfArray[10] = 6;  // gzip eXtra LENgth 
            bgzfArray[11] = 0;
            bgzfArray[12] = 66; // Subfield Identifier1
            bgzfArray[13] = 67; // Subfield Identifier2
            bgzfArray[14] = 2;  // Subfield LENgth
            bgzfArray[15] = 0;

            byte[] intvalue = Helper.GetLittleEndianByteArray((UInt16)(blockSize - 1));

            bgzfArray[16] = intvalue[0];
            bgzfArray[17] = intvalue[1];
            //start at 10 to skip the gzip header which was already added above
            for (int i = 10; i < compressedStream.Length; i++)
            {
                bgzfArray[i + 8] = compressedArray[i];
            }

            return bgzfArray;
        }