2 To build the snappytool binary:
3 g++ main.cpp /usr/lib/libsnappy.a -o snappytool
4 or, if you have built the C++ snappy library from source:
5 g++ main.cpp /path/to/your/snappy/.libs/libsnappy.a -o snappytool
6 after running "make" from your snappy checkout directory.
21 int main(int argc, char** argv) {
24 fprintf(stderr, "exactly one of -d or -e must be given\n");
27 bool decode = strcmp(argv[1], "-d") == 0;
28 bool encode = strcmp(argv[1], "-e") == 0;
29 if (decode == encode) {
30 fprintf(stderr, "exactly one of -d or -e must be given\n");
34 // Read all of stdin into src[:s].
38 fprintf(stderr, "input too large\n");
41 ssize_t n = read(0, src+s, N-s);
46 fprintf(stderr, "read error: %s\n", strerror(errno));
47 // TODO: handle EAGAIN, EINTR?
53 // Encode or decode src[:s] to dst[:d], and write to stdout.
56 if (N < snappy::MaxCompressedLength(s)) {
57 fprintf(stderr, "input too large after encoding\n");
60 snappy::RawCompress(src, s, dst, &d);
62 if (!snappy::GetUncompressedLength(src, s, &d)) {
63 fprintf(stderr, "could not get uncompressed length\n");
67 fprintf(stderr, "input too large after decoding\n");
70 if (!snappy::RawUncompress(src, s, dst)) {
71 fprintf(stderr, "input was not valid Snappy-compressed data\n");