Compress() public static method

Assigns a compressed verion of InputByteArray to OutputByteArray
public static Compress ( byte InputByteArray, byte &OutputByteArray ) : void
InputByteArray byte The byte array that is to be compressed
OutputByteArray byte The byte array into which the compressed data /// is to be written. This array must be allocated before calling the method, and /// it must be large enough to contain the compressed data. Note that if the data /// in InputByteArray is highly incompressible (floating point data that uses its /// full precision range is a known example), then OutputByteArray may need to be /// slightly larger than the InputByteArray. This method will resize OutputByteArray /// so that its allocated size is no larger than the data it contains.
return void
コード例 #1
0
        /// <summary>
        /// This returns a compressed version of the given byte array
        /// </summary>
        /// <param name="uncompressedBlob">the uncompressed byte array</param>
        /// <param name="compressionCode">a generation number that indicates what compression technique to use</param>
        /// <returns>the compressed byte array</returns>
        public static unsafe Byte[] CompressBlob(Byte[] uncompressedBlob, int compressionCode)
        {
            if (compressionCode == 1)
            {
                Byte[] compressedBlob;
                // the byte-array length of the input blob
                int inputLength = uncompressedBlob.Length;
                // The byte array that will be created by the compression.
                // Note that some incompressible BLOBs will actually be made larger by LZFX
                // compression.  We have observed about 1% increase over the original BLOB,
                // so the factor of 1.05 is expected to be safe.  We add 16 since the factor
                // of 1.05 is insufficient when the BLOB is very small.
                compressedBlob = new Byte[(int)(inputLength * 1.05) + 16];

                // Compress using LZFX algorithm.
                // This method resizes the compressed byte array for us.
                LZFX.Compress(uncompressedBlob, ref compressedBlob);
                return(compressedBlob);
            }
            if (compressionCode == 2)
            {
                Byte[] compressedBlob;
                // the byte-array length of the input blob
                int inputLength = uncompressedBlob.Length;
                // The byte array that will be created by the compression.
                // Note that some incompressible BLOBs might actually be made larger by LZ4
                // compression.  The GetMaxSize method calls a function built into LZ4 which
                // returns the maximum possible size of the output array. LZ4 documentation suggests
                // that speed is optimized by allocating this max size.
                compressedBlob = new Byte[(int)LZ4.GetMaxSize(inputLength)];

                // Compress using LZ4 algorithm.
                // This method resizes the compressed byte array for us.
                LZ4.Compress(uncompressedBlob, ref compressedBlob, 4);
                return(compressedBlob);
            }
            else
            {   // return without doing any compression
                return(uncompressedBlob);
            }
        }