Skip to content

Instantly share code, notes, and snippets.

@fuzz-ai
Created December 8, 2018 06:35
snappy compression round-trip test harness
#include <snappy.h>
#include <iostream>
#include <string>
#include <cstring>
#include <stdlib.h>
const size_t maxInputSize = 10 * 1024 * 1024;
char inputBuf[maxInputSize];
int main( int argc, char *argv[] ) {
std::cin.read( inputBuf, maxInputSize );
size_t inputLength = std::cin.gcount();
std::string compressed;
snappy::Compress( inputBuf, inputLength, &compressed );
std::string uncompressed;
snappy::Uncompress( compressed.data(), compressed.size(),
&uncompressed );
if ( uncompressed.size() != inputLength ) {
std::cout << "Size mismatch.";
abort();
}
if ( memcmp( uncompressed.data(), inputBuf, inputLength ) != 0 ) {
std::cout << "Content mismatch.";
abort();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment