Exemplo n.º 1
0
        public static int Uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int outputLength)
        {
            Ensure.IsNotNull(input, nameof(input));
            Ensure.IsNotNull(output, nameof(output));
            EnsureBufferRangeIsValid(inputOffset, inputLength, input.Length);
            EnsureBufferRangeIsValid(outputOffset, outputLength, output.Length);

            if (inputLength == 0)
            {
                throw new InvalidDataException("Compressed block cannot be empty.");
            }

            var status = SnappyAdapter.snappy_uncompress(input, inputOffset, inputLength, output, outputOffset, ref outputLength);

            switch (status)
            {
            case SnappyStatus.Ok:
                return(outputLength);

            case SnappyStatus.BufferTooSmall:
                throw new ArgumentOutOfRangeException("Output array is too small.");

            default:
                throw new InvalidDataException("Input is not a valid snappy-compressed block.");
            }
        }
Exemplo n.º 2
0
        public static bool Validate(byte[] input, int inputOffset, int inputLength)
        {
            Ensure.IsNotNull(input, nameof(input));
            EnsureBufferRangeIsValid(inputOffset, inputLength, input.Length);
            if (inputLength == 0)
            {
                return(false);
            }

            return(SnappyAdapter.snappy_validate_compressed_buffer(input, inputOffset, inputLength) == SnappyStatus.Ok);
        }
Exemplo n.º 3
0
        public static int GetUncompressedLength(byte[] input, int inputOffset, int inputLength)
        {
            Ensure.IsNotNull(input, nameof(input));
            EnsureBufferRangeIsValid(inputOffset, inputLength, input.Length);
            if (inputLength == 0)
            {
                throw new InvalidDataException("Compressed block cannot be empty.");
            }

            var status = SnappyAdapter.snappy_uncompressed_length(input, inputOffset, inputLength, out var outputLength);

            switch (status)
            {
            case SnappyStatus.Ok:
                return(outputLength);

            default:
                throw new InvalidDataException("Input is not a valid snappy-compressed block.");
            }
        }
Exemplo n.º 4
0
 public static int GetMaxCompressedLength(int inputLength)
 {
     return(SnappyAdapter.snappy_max_compressed_length(inputLength));
 }