C++压缩解压之snappy

C++压缩解压之snappy引文出处 http wiki dreamrunner org public html C C Library Notes Snappy htmlSnappyTa nbsp http google github io snappy git nbsp https github com

引文出处:http://wiki.dreamrunner.org/public_html/C-C++/Library-Notes/Snappy.html

Snappy

Table of Contents

Overview

  • homepage: http://google.github.io/snappy/
  • git: https://github.com/google/snappy

Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression

  • Fast: Compression speeds at 250 MB/sec and beyond, with no assembler code. See “Performance” below.
  • Stable: Over the last few years, Snappy has compressed and decompressed petabytes of data in Google’s production environment. The Snappy bitstream format is stable and will not change between versions.
  • Robust: The Snappy decompressor is designed not to crash in the face of corrupted or malicious input.

Compile and install

./autogen.sh ./configure make # to static library ar rcs libsnappy.a ./*.o 

Use

To use Snappy from your own C++ program, include the file “snappy.h” from your calling file, and link against the compiled library.

There are many ways to call Snappy, but the simplest possible is

snappy::Compress(input.data(), input.size(), &output); snappy::Uncompress(input.data(), input.size(), &output); 

where “input” and “output” are both instances of std::string.

Example

#include  
       #include  
       #include  
       using namespace std; int main() { string input = "Hello World"; string output; for (int i = 0; i < 5; ++i) { input += input; } snappy::Compress(input.data(), input.size(), &output); cout << "input size:" << input.size() << " output size:" << output.size() << endl; string output_uncom; snappy::Uncompress(output.data(), output.size(), &output_uncom); if (input == output_uncom) { cout << "Equal" << endl; } else { cout << "ERROR: not equal" << endl; } return 0; } 

$ g++ -o example ./snappy-example.cc -I. -L. -lsnappy $ ./example input size:352 output size:32 Equal 

Author: Shi Shougang

Created: 2016-03-13 Sun 22:15

Emacs 24.3.1 (Org mode 8.2.10)

Validate

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/224731.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午11:16
下一篇 2026年3月17日 上午11:16


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号