コード例 #1
0
ファイル: Interop.cs プロジェクト: SpeedReflect/Nikki
        /// <summary>
        /// Compresses buffer based on compression type passed.
        /// </summary>
        /// <param name="input">Array to compress.</param>
        /// <param name="start">Start index of compression.</param>
        /// <param name="count">Number of bytes to compress.</param>
        /// <param name="type">Type of the compression.</param>
        /// <returns>Compressed data.</returns>
        public static byte[] Compress(byte[] input, int start, int count, LZCompressionType type)
        {
            if (input == null)
            {
                return(null);
            }
            if (start < 0 || count <= 0)
            {
                return(null);
            }
            if (start + count > input.Length)
            {
                return(null);
            }

            var output  = new byte[count << 1];
            int outsize = 0;

            unsafe
            {
                fixed(byte *inptr = &input[start])
                {
                    fixed(byte *outptr = &output[0])
                    {
                        lock (Interop._s_lock)
                        {
                            outsize = PrivateEncode(inptr, count, outptr, (int)type);
                        }
                    }
                }
            }

            Array.Resize(ref output, outsize);
            return(output);
        }
コード例 #2
0
ファイル: Interop.cs プロジェクト: SpeedReflect/Nikki
        /// <summary>
        /// Compresses buffer based on compression type passed.
        /// </summary>
        /// <param name="input">Array to compress.</param>
        /// <param name="type">Type of the compression.</param>
        /// <returns>Compressed data.</returns>
        public static byte[] Compress(byte[] input, LZCompressionType type)
        {
            if (input == null)
            {
                return(null);
            }

            var output  = new byte[input.Length << 1];
            int outsize = 0;

            lock (Interop._s_lock)
            {
                outsize = PrivateEncode(input, input.Length, output, (int)type);
            }

            Array.Resize(ref output, outsize);
            return(output);
        }