Internal changes
diff --git a/snappy-c.cc b/snappy-c.cc index 6da18d8..fc2d5d3 100644 --- a/snappy-c.cc +++ b/snappy-c.cc
@@ -45,6 +45,25 @@ return SNAPPY_OK; } +snappy_status snappy_compress_with_level(const char* input, size_t input_length, + int compression_level, + char* compressed, + size_t* compressed_length) { + if (*compressed_length < snappy_max_compressed_length(input_length)) { + return SNAPPY_BUFFER_TOO_SMALL; + } + if (compression_level < SNAPPY_MIN_COMPRESSION_LEVEL || + compression_level > SNAPPY_MAX_COMPRESSION_LEVEL) { + return SNAPPY_INVALID_INPUT; + } + snappy::RawCompress(input, input_length, compressed, compressed_length, + snappy::CompressionOptions{/*level=*/compression_level}); + if (*compressed_length == 0) { + return SNAPPY_INVALID_INPUT; + } + return SNAPPY_OK; +} + snappy_status snappy_uncompress(const char* compressed, size_t compressed_length, char* uncompressed,
diff --git a/snappy-c.h b/snappy-c.h index e228785..4dfdcdb 100644 --- a/snappy-c.h +++ b/snappy-c.h
@@ -57,7 +57,8 @@ * If it is not at least equal to "snappy_max_compressed_length(input_length)", * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression, * <compressed_length> contains the true length of the compressed output, - * and SNAPPY_OK is returned. + * and SNAPPY_OK is returned. Compression level is 1. For using other + * compression levels, call snappy_compress_with_level. * * An <input_length> of 2^32 or more returns SNAPPY_INVALID_INPUT with * <compressed_length> set to 0 and nothing written. @@ -71,10 +72,20 @@ * } * free(output); */ -snappy_status snappy_compress(const char* input, - size_t input_length, - char* compressed, - size_t* compressed_length); +snappy_status snappy_compress(const char* input, size_t input_length, + char* compressed, size_t* compressed_length); + +/* + * Same as above but uses compression_level which must be between + * SNAPPY_MIN_COMPRESSION_LEVEL and SNAPPY_MAX_COMPRESSION_LEVEL. + */ +#define SNAPPY_MIN_COMPRESSION_LEVEL 1 +#define SNAPPY_MAX_COMPRESSION_LEVEL 2 + +snappy_status snappy_compress_with_level(const char* input, size_t input_length, + int compression_level, + char* compressed, + size_t* compressed_length); /* * Given data in "compressed[0..compressed_length-1]" generated by
diff --git a/snappy_unittest.cc b/snappy_unittest.cc index db60f1d..57d617b 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc
@@ -545,7 +545,7 @@ } TEST(Snappy, CompressionContext) { - std::minstd_rand0 rng(absl::GetFlag(FLAGS_test_random_seed)); + std::minstd_rand0 rng(snappy::GetFlag(FLAGS_test_random_seed)); std::uniform_int_distribution<int> uniform_byte(0, 255); // A single context, reused across every compression below.