近日需要在毕业设计中引入一个压缩库,要求压缩与解压缩速度快,但是压缩率可以不那么苛刻。查找资料发现Google的snappy库比较合适,而且该库开源,由C++写成。所以就拿来使用一下,下面权作记录。下面引出的任何涉及Google公司的源代码,版权归Google公司所有,我权作学习交流。文章安排如下,首先简要介绍Snappy,之后安装之,然后以实际例子介绍如何使用,接着bzip2和gzip做了性能比较,最后提出一些使用上面的疑问。

(一)简要介绍

去官网下载之http://code.google.com/p/snappy/。在Project Home处有这么一段英文,我想许多地方都引用和翻译了这段。我也尝试翻译一下。

Snappy is a compression/decompression library.

It does not aim for maximum compression,

or compatibility with any other compression library;

instead, it aims for veryhigh speeds and reasonable compression.

For instance, compared to the fastest mode of zlib,

Snappy is an order of magnitude faster for most inputs,

but the resulting compressed files are anywhere from 20% to 100% bigger.

On a single core of a Core i7 processor in 64-bit mode,

Snappy compresses at about 250 MB/sec or more and

decompresses at about 500 MB/sec or more.

Snappy is widely used inside Google, in everything from BigTable

and MapReduce to our internal RPC systems.

译文:Snappy是一个压缩/解压缩库。它不是以最大压缩率,或者与其他压缩库兼容为目标;它旨在获得高速的压缩和合理的压缩率。例如,Snappy对大多数的输入比zlib的最快模式要快几个数量级,但是其压缩过后的文件通常会比zlib大20%到100%。在Core i7的单核64位模式下,Snappy压缩速度大概可以达到250MB/s或者更快,解压缩可以达到大约500MB/s或更快。

Snappy在Google内部广泛使用,从BigTable,MapReduce到公司内部的RPC系统。

(二)安装过程

下面描述安装过程:

下载snappy-1.0.5.tar.gz,snappy的安装过程与传统的安装过程一样。解压后的INSTALL文件有详细的安装说明。

gunzip snappy-1.0.5.tar.gz

tar xf snappy-1.0.5.tar

cd snappy-1.0.5

./configure

make

make install

安装完成后,生成的动态库和静态库位于/usr/local/lib处,编程需要用到的头文件位于/usr/local/include处。注意需要将这些库文件cp至/usr/lib处,不然就算在链接的时候加上-L/usr/local/lib,在运行时也会报错。./main: error while loading shared libraries: libsnappy.so.1:

cannot open shared object file: No such file or directory

当然这是我的LD_LIBRARY_PATH环境变量的设置问题。

(三)使用snappy

解压出来的README文件介绍了一简单的使用方式。snappy是各种库标示符所在的命名空间。C++使用需要包含#include <snappy.h>头文件,C语言使用需要包含#include<snapyy-c.h>头文件。Snappy使用较为简单,我指的是跟bzip2的库比起来。所有的函数接口都暴露在上述两个头文件中,头文件中有详细的使用说明,并有简单的示例,而且英文通俗易懂。摘抄如下(Google公司版权所有):

snappy.h

[cpp] view plain copy print ?
  1. // Copyright 2005 and onwards Google Inc.
  2. //
  3. // Redistribution and use in source and binary forms, with or without
  4. // modification, are permitted provided that the following conditions are
  5. // met:
  6. //
  7. //     * Redistributions of source code must retain the above copyright
  8. // notice, this list of conditions and the following disclaimer.
  9. //     * Redistributions in binary form must reproduce the above
  10. // copyright notice, this list of conditions and the following disclaimer
  11. // in the documentation and/or other materials provided with the
  12. // distribution.
  13. //     * Neither the name of Google Inc. nor the names of its
  14. // contributors may be used to endorse or promote products derived from
  15. // this software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. //
  29. // A light-weight compression algorithm.  It is designed for speed of
  30. // compression and decompression, rather than for the utmost in space
  31. // savings.
  32. //
  33. // For getting better compression ratios when you are compressing data
  34. // with long repeated sequences or compressing data that is similar to
  35. // other data, while still compressing fast, you might look at first
  36. // using BMDiff and then compressing the output of BMDiff with
  37. // Snappy.
  38. #ifndef UTIL_SNAPPY_SNAPPY_H__
  39. #define UTIL_SNAPPY_SNAPPY_H__
  40. #include <stddef.h>
  41. #include <string>
  42. #include "snappy-stubs-public.h"
  43. namespace snappy {
  44. class Source;
  45. class Sink;
  46. // ------------------------------------------------------------------------
  47. // Generic compression/decompression routines.
  48. // ------------------------------------------------------------------------
  49. // Compress the bytes read from "*source" and append to "*sink". Return the
  50. // number of bytes written.
  51. size_t Compress(Source* source, Sink* sink);
  52. bool GetUncompressedLength(Source* source, uint32* result);
  53. // ------------------------------------------------------------------------
  54. // Higher-level string based routines (should be sufficient for most users)
  55. // ------------------------------------------------------------------------
  56. // Sets "*output" to the compressed version of "input[0,input_length-1]".
  57. // Original contents of *output are lost.
  58. //
  59. // REQUIRES: "input[]" is not an alias of "*output".
  60. size_t Compress(const char* input, size_t input_length, string* output);
  61. // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed".
  62. // Original contents of "*uncompressed" are lost.
  63. //
  64. // REQUIRES: "compressed[]" is not an alias of "*uncompressed".
  65. //
  66. // returns false if the message is corrupted and could not be decompressed
  67. bool Uncompress(const char* compressed, size_t compressed_length,
  68. string* uncompressed);
  69. // ------------------------------------------------------------------------
  70. // Lower-level character array based routines.  May be useful for
  71. // efficiency reasons in certain circumstances.
  72. // ------------------------------------------------------------------------
  73. // REQUIRES: "compressed" must point to an area of memory that is at
  74. // least "MaxCompressedLength(input_length)" bytes in length.
  75. //
  76. // Takes the data stored in "input[0..input_length]" and stores
  77. // it in the array pointed to by "compressed".
  78. //
  79. // "*compressed_length" is set to the length of the compressed output.
  80. //
  81. // Example:
  82. //    char* output = new char[snappy::MaxCompressedLength(input_length)];
  83. //    size_t output_length;
  84. //    RawCompress(input, input_length, output, &output_length);
  85. //    ... Process(output, output_length) ...
  86. //    delete [] output;
  87. void RawCompress(const char* input,
  88. size_t input_length,
  89. char* compressed,
  90. size_t* compressed_length);
  91. // Given data in "compressed[0..compressed_length-1]" generated by
  92. // calling the Snappy::Compress routine, this routine
  93. // stores the uncompressed data to
  94. //    uncompressed[0..GetUncompressedLength(compressed)-1]
  95. // returns false if the message is corrupted and could not be decrypted
  96. bool RawUncompress(const char* compressed, size_t compressed_length,
  97. char* uncompressed);
  98. // Given data from the byte source 'compressed' generated by calling
  99. // the Snappy::Compress routine, this routine stores the uncompressed
  100. // data to
  101. //    uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1]
  102. // returns false if the message is corrupted and could not be decrypted
  103. bool RawUncompress(Source* compressed, char* uncompressed);
  104. // Returns the maximal size of the compressed representation of
  105. // input data that is "source_bytes" bytes in length;
  106. size_t MaxCompressedLength(size_t source_bytes);
  107. // REQUIRES: "compressed[]" was produced by RawCompress() or Compress()
  108. // Returns true and stores the length of the uncompressed data in
  109. // *result normally.  Returns false on parsing error.
  110. // This operation takes O(1) time.
  111. bool GetUncompressedLength(const char* compressed, size_t compressed_length,
  112. size_t* result);
  113. // Returns true iff the contents of "compressed[]" can be uncompressed
  114. // successfully.  Does not return the uncompressed data.  Takes
  115. // time proportional to compressed_length, but is usually at least
  116. // a factor of four faster than actual decompression.
  117. bool IsValidCompressedBuffer(const char* compressed,
  118. size_t compressed_length);
  119. // *** DO NOT CHANGE THE VALUE OF kBlockSize ***
  120. //
  121. // New Compression code chops up the input into blocks of at most
  122. // the following size.  This ensures that back-references in the
  123. // output never cross kBlockSize block boundaries.  This can be
  124. // helpful in implementing blocked decompression.  However the
  125. // decompression code should not rely on this guarantee since older
  126. // compression code may not obey it.
  127. static const int kBlockLog = 15;
  128. static const size_t kBlockSize = 1 << kBlockLog;
  129. static const int kMaxHashTableBits = 14;
  130. static const size_t kMaxHashTableSize = 1 << kMaxHashTableBits;
  131. }  // end namespace snappy
  132. #endif  // UTIL_SNAPPY_SNAPPY_H__
// Copyright 2005 and onwards Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// A light-weight compression algorithm.  It is designed for speed of
// compression and decompression, rather than for the utmost in space
// savings.
//
// For getting better compression ratios when you are compressing data
// with long repeated sequences or compressing data that is similar to
// other data, while still compressing fast, you might look at first
// using BMDiff and then compressing the output of BMDiff with
// Snappy.#ifndef UTIL_SNAPPY_SNAPPY_H__
#define UTIL_SNAPPY_SNAPPY_H__#include <stddef.h>
#include <string>#include "snappy-stubs-public.h"namespace snappy {class Source;class Sink;// ------------------------------------------------------------------------// Generic compression/decompression routines.// ------------------------------------------------------------------------// Compress the bytes read from "*source" and append to "*sink". Return the// number of bytes written.size_t Compress(Source* source, Sink* sink);bool GetUncompressedLength(Source* source, uint32* result);// ------------------------------------------------------------------------// Higher-level string based routines (should be sufficient for most users)// ------------------------------------------------------------------------// Sets "*output" to the compressed version of "input[0,input_length-1]".// Original contents of *output are lost.//// REQUIRES: "input[]" is not an alias of "*output".size_t Compress(const char* input, size_t input_length, string* output);// Decompresses "compressed[0,compressed_length-1]" to "*uncompressed".// Original contents of "*uncompressed" are lost.//// REQUIRES: "compressed[]" is not an alias of "*uncompressed".//// returns false if the message is corrupted and could not be decompressedbool Uncompress(const char* compressed, size_t compressed_length,string* uncompressed);// ------------------------------------------------------------------------// Lower-level character array based routines.  May be useful for// efficiency reasons in certain circumstances.// ------------------------------------------------------------------------// REQUIRES: "compressed" must point to an area of memory that is at// least "MaxCompressedLength(input_length)" bytes in length.//// Takes the data stored in "input[0..input_length]" and stores// it in the array pointed to by "compressed".//// "*compressed_length" is set to the length of the compressed output.//// Example://    char* output = new char[snappy::MaxCompressedLength(input_length)];//    size_t output_length;//    RawCompress(input, input_length, output, &output_length);//    ... Process(output, output_length) ...//    delete [] output;void RawCompress(const char* input,size_t input_length,char* compressed,size_t* compressed_length);// Given data in "compressed[0..compressed_length-1]" generated by// calling the Snappy::Compress routine, this routine// stores the uncompressed data to//    uncompressed[0..GetUncompressedLength(compressed)-1]// returns false if the message is corrupted and could not be decryptedbool RawUncompress(const char* compressed, size_t compressed_length,char* uncompressed);// Given data from the byte source 'compressed' generated by calling// the Snappy::Compress routine, this routine stores the uncompressed// data to//    uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1]// returns false if the message is corrupted and could not be decryptedbool RawUncompress(Source* compressed, char* uncompressed);// Returns the maximal size of the compressed representation of// input data that is "source_bytes" bytes in length;size_t MaxCompressedLength(size_t source_bytes);// REQUIRES: "compressed[]" was produced by RawCompress() or Compress()// Returns true and stores the length of the uncompressed data in// *result normally.  Returns false on parsing error.// This operation takes O(1) time.bool GetUncompressedLength(const char* compressed, size_t compressed_length,size_t* result);// Returns true iff the contents of "compressed[]" can be uncompressed// successfully.  Does not return the uncompressed data.  Takes// time proportional to compressed_length, but is usually at least// a factor of four faster than actual decompression.bool IsValidCompressedBuffer(const char* compressed,size_t compressed_length);// *** DO NOT CHANGE THE VALUE OF kBlockSize ***//// New Compression code chops up the input into blocks of at most// the following size.  This ensures that back-references in the// output never cross kBlockSize block boundaries.  This can be// helpful in implementing blocked decompression.  However the// decompression code should not rely on this guarantee since older// compression code may not obey it.static const int kBlockLog = 15;static const size_t kBlockSize = 1 << kBlockLog;static const int kMaxHashTableBits = 14;static const size_t kMaxHashTableSize = 1 << kMaxHashTableBits;}  // end namespace snappy#endif  // UTIL_SNAPPY_SNAPPY_H__

snapp-c.h

[cpp] view plain copy print ?
  1. /*
  2. * Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. *     * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *     * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. *     * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * Plain C interface (a wrapper around the C++ implementation).
  31. */
  32. #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
  33. #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. #include <stddef.h>
  38. /*
  39. * Return values; see the documentation for each function to know
  40. * what each can return.
  41. */
  42. typedef enum {
  43. SNAPPY_OK = 0,
  44. SNAPPY_INVALID_INPUT = 1,
  45. SNAPPY_BUFFER_TOO_SMALL = 2,
  46. } snappy_status;
  47. /*
  48. * Takes the data stored in "input[0..input_length-1]" and stores
  49. * it in the array pointed to by "compressed".
  50. *
  51. * <compressed_length> signals the space available in "compressed".
  52. * If it is not at least equal to "snappy_max_compressed_length(input_length)",
  53. * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression,
  54. * <compressed_length> contains the true length of the compressed output,
  55. * and SNAPPY_OK is returned.
  56. *
  57. * Example:
  58. *   size_t output_length = snappy_max_compressed_length(input_length);
  59. *   char* output = (char*)malloc(output_length);
  60. *   if (snappy_compress(input, input_length, output, &output_length)
  61. *       == SNAPPY_OK) {
  62. *     ... Process(output, output_length) ...
  63. *   }
  64. *   free(output);
  65. */
  66. snappy_status snappy_compress(const char* input,
  67. size_t input_length,
  68. char* compressed,
  69. size_t* compressed_length);
  70. /*
  71. * Given data in "compressed[0..compressed_length-1]" generated by
  72. * calling the snappy_compress routine, this routine stores
  73. * the uncompressed data to
  74. *   uncompressed[0..uncompressed_length-1].
  75. * Returns failure (a value not equal to SNAPPY_OK) if the message
  76. * is corrupted and could not be decrypted.
  77. *
  78. * <uncompressed_length> signals the space available in "uncompressed".
  79. * If it is not at least equal to the value returned by
  80. * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL
  81. * is returned. After successful decompression, <uncompressed_length>
  82. * contains the true length of the decompressed output.
  83. *
  84. * Example:
  85. *   size_t output_length;
  86. *   if (snappy_uncompressed_length(input, input_length, &output_length)
  87. *       != SNAPPY_OK) {
  88. *     ... fail ...
  89. *   }
  90. *   char* output = (char*)malloc(output_length);
  91. *   if (snappy_uncompress(input, input_length, output, &output_length)
  92. *       == SNAPPY_OK) {
  93. *     ... Process(output, output_length) ...
  94. *   }
  95. *   free(output);
  96. */
  97. snappy_status snappy_uncompress(const char* compressed,
  98. size_t compressed_length,
  99. char* uncompressed,
  100. size_t* uncompressed_length);
  101. /*
  102. * Returns the maximal size of the compressed representation of
  103. * input data that is "source_length" bytes in length.
  104. */
  105. size_t snappy_max_compressed_length(size_t source_length);
  106. /*
  107. * REQUIRES: "compressed[]" was produced by snappy_compress()
  108. * Returns SNAPPY_OK and stores the length of the uncompressed data in
  109. * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error.
  110. * This operation takes O(1) time.
  111. */
  112. snappy_status snappy_uncompressed_length(const char* compressed,
  113. size_t compressed_length,
  114. size_t* result);
  115. /*
  116. * Check if the contents of "compressed[]" can be uncompressed successfully.
  117. * Does not return the uncompressed data; if so, returns SNAPPY_OK,
  118. * or if not, returns SNAPPY_INVALID_INPUT.
  119. * Takes time proportional to compressed_length, but is usually at least a
  120. * factor of four faster than actual decompression.
  121. */
  122. snappy_status snappy_validate_compressed_buffer(const char* compressed,
  123. size_t compressed_length);
  124. #ifdef __cplusplus
  125. }  // extern "C"
  126. #endif
  127. #endif  /* UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */
/** Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions are* met:**     * Redistributions of source code must retain the above copyright* notice, this list of conditions and the following disclaimer.*     * Redistributions in binary form must reproduce the above* copyright notice, this list of conditions and the following disclaimer* in the documentation and/or other materials provided with the* distribution.*     * Neither the name of Google Inc. nor the names of its* contributors may be used to endorse or promote products derived from* this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.** Plain C interface (a wrapper around the C++ implementation).*/#ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
#define UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_#ifdef __cplusplus
extern "C" {
#endif#include <stddef.h>/** Return values; see the documentation for each function to know* what each can return.*/
typedef enum {SNAPPY_OK = 0,SNAPPY_INVALID_INPUT = 1,SNAPPY_BUFFER_TOO_SMALL = 2,
} snappy_status;/** Takes the data stored in "input[0..input_length-1]" and stores* it in the array pointed to by "compressed".** <compressed_length> signals the space available in "compressed".* 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.** Example:*   size_t output_length = snappy_max_compressed_length(input_length);*   char* output = (char*)malloc(output_length);*   if (snappy_compress(input, input_length, output, &output_length)*       == SNAPPY_OK) {*     ... Process(output, output_length) ...*   }*   free(output);*/
snappy_status snappy_compress(const char* input,size_t input_length,char* compressed,size_t* compressed_length);/** Given data in "compressed[0..compressed_length-1]" generated by* calling the snappy_compress routine, this routine stores* the uncompressed data to*   uncompressed[0..uncompressed_length-1].* Returns failure (a value not equal to SNAPPY_OK) if the message* is corrupted and could not be decrypted.** <uncompressed_length> signals the space available in "uncompressed".* If it is not at least equal to the value returned by* snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL* is returned. After successful decompression, <uncompressed_length>* contains the true length of the decompressed output.** Example:*   size_t output_length;*   if (snappy_uncompressed_length(input, input_length, &output_length)*       != SNAPPY_OK) {*     ... fail ...*   }*   char* output = (char*)malloc(output_length);*   if (snappy_uncompress(input, input_length, output, &output_length)*       == SNAPPY_OK) {*     ... Process(output, output_length) ...*   }*   free(output);*/
snappy_status snappy_uncompress(const char* compressed,size_t compressed_length,char* uncompressed,size_t* uncompressed_length);/** Returns the maximal size of the compressed representation of* input data that is "source_length" bytes in length.*/
size_t snappy_max_compressed_length(size_t source_length);/** REQUIRES: "compressed[]" was produced by snappy_compress()* Returns SNAPPY_OK and stores the length of the uncompressed data in* *result normally. Returns SNAPPY_INVALID_INPUT on parsing error.* This operation takes O(1) time.*/
snappy_status snappy_uncompressed_length(const char* compressed,size_t compressed_length,size_t* result);/** Check if the contents of "compressed[]" can be uncompressed successfully.* Does not return the uncompressed data; if so, returns SNAPPY_OK,* or if not, returns SNAPPY_INVALID_INPUT.* Takes time proportional to compressed_length, but is usually at least a* factor of four faster than actual decompression.*/
snappy_status snappy_validate_compressed_buffer(const char* compressed,size_t compressed_length);#ifdef __cplusplus
}  // extern "C"
#endif#endif  /* UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */

Snappy压缩库安装和使用之一相关推荐

  1. hadoopsnappy解压_Hadoop Snappy 压缩的安装和配置

    snappy是google的一个开源的压缩库,在合理的压缩率的前提下提供了提供了一个很高的压缩/解压的速度,利用单颗Intel Corei7处理器内核处理达到每秒处理250MB~500MB的数据流.s ...

  2. hadoop添加snappy解压缩库

    Snappy是用C++开发的压缩和解压缩开发包,旨在提供高速压缩速度和合理的压缩率. 虽然生成的压缩文件可能会比其他压缩库的要大上20%至100%,但是,相比其他的压缩库,Snappy却能够在特定的压 ...

  3. Hadoop集群中添加Snappy解压缩库

    Snappy是用C++开发的压缩和解压缩开发包,旨在提供高速压缩速度和合理的压缩率.Snappy比zlib更快,但文件相对要大20%到100%.在64位模式的Core i7处理器上,可达每秒250~5 ...

  4. DCMTK3.6.0(MD支持库)安装说明-无图版

    不知道为啥ItEye只能显示日志文字的部分内容,本篇日志完整版,可以看我的最新博客地址: 网易博客地址:DCMTK3.6.0(MD支持库)安装说明 一.运行环境:WIN7 32bit + Visual ...

  5. DCMTK3.6.0(MD支持库)安装说明

    前言: 虽然写了这么一大堆,实际过程很简单,大家耐心看完,绝对能成功.我已经在我的办公电脑和我的影像工作站上,都成功实现了.(简单文字版,请看这篇<DCMTK3.6.0(MD支持库)安装说明-无 ...

  6. DCMTK3.6.0 (MT支持库)安装 完整说明

    6月7日 13:58 更新 MD项目的,请参考这篇 <DCMTK3.6.0(MD支持库)安装说明> 6月6日晚22:38更新 经过2天冥思苦想都没解决的问题,在我晚上打完乒乓球之后,终于解 ...

  7. Hadoop/HBase 配置snappy压缩

    Hadoop/HBase 开启snappy压缩 参考链接 hadoop-snappy Google Code snappy.compression hbase docs cnblogs参考资料 ins ...

  8. 高翔视觉SLAM十四讲(第二版)各种软件、库安装的以及报错解决方法

    目录 前言 系统版本 下载高翔视觉SLAM十四讲第二版的源代码 一.安装 Vim 二.安装 g++ 三.安装 KDevelop 以及汉化 1.安装 2.汉化 四.安装 Eigen 库 五.安装 Pan ...

  9. 01-SNAP与snappy介绍及安装

    转载自:https://blog.csdn.net/lidahuilidahui/article/details/99679554 01-SNAP与snappy介绍及安装 前言 关于SNAP SNAP ...

最新文章

  1. 报名 | 美团是怎样给你推荐外卖的?美团大脑知识图谱详解
  2. 简易快速的开发,需要一个快速开发平台来支持
  3. python快速入门答案-Python 快速入门笔记(1):简介
  4. 阿里云OSS存储开发
  5. python访问数据库oracle_python连接oracle数据库
  6. 聊聊 MySql 索引那些事儿
  7. opencv 图像旋转_用Dlib和OpenCV还能做什么?这个开源项目实现了驾驶员疲劳检测...
  8. ITK:二进制XOR两个图像
  9. Selenium定位多个iframe嵌套中的元素
  10. 知识图谱属性与关系区别
  11. Datalogic得利捷携突破性无线充电技术推出三款最新产品
  12. 数据揭秘共享单车新局势:ofo多项行业第一
  13. SCDM学习笔记(6)
  14. 使用pdfbox-2.0.1.jar将pdf转换成图片,并且可自定义图片大小
  15. 重装系统后,文件数据被格式化如何恢复?
  16. shader拖尾_u3d拖尾特效组件-------TrailRenderer
  17. [附源码]JAVA+ssm计算机毕业设计房屋租赁管理系统设计(程序+Lw)
  18. 教你win10更新失败怎么解决,win10系统更新失败怎么办
  19. 基础30讲 第11讲 多元函数微分学
  20. 基于PHP大学生英语在线教学网

热门文章

  1. 嵌入式 独立看门狗实验
  2. oracle初始化参数详解
  3. 华为首次超越苹果 iPhone失去全球第二大手机供应商
  4. 不知不觉发财10大秘诀(转)
  5. 华为网工入门之eNSP小实验(2)--DNS(Domain Name System)域名系统
  6. AI一分钟 | 无人驾驶技术排名:百度居中游,苹果特斯拉垫底;Google在深圳设立办公室
  7. 使用 Python3 获取网页源代码
  8. 金丝楠PhoebeSheareri
  9. 查询快递物流提前签收的单号,快速分析筛选的方法
  10. php 怎么打印条形码,php – 直接从(zebra)打印机上的浏览器打印贴纸/条形码标签...