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


相关推荐

  • SD/MMC卡初始化及读写流程[通俗易懂]

    SD/MMC卡初始化及读写流程[通俗易懂]二、MMC/SD卡的模型和工作原理PIN脚、SD卡总线、SD卡结构、SD卡寄存器、上电过程SD卡寄存器: OCR:操作电压寄存器:只读,32位第31位: 表示卡上电的状态位  CID:卡身份识别寄存器只读128位生产厂商、产品ID,生产日期和串号等  CSD:部分可写128位卡的容量、擦出扇区大小、读写最大数据块的大小、读操作的电流、电压等等 

    2022年5月20日
    45
  • sklearn.KFold用法示例

    sklearn.KFold用法示例sklearn.KFold用法示例参数解释用法示例参数解释classsklearn.model_selection.KFold(n_splits=’warn’,shuffle=False,random_state=None)API文档将训练/测试数据集划分n_splits个互斥子集,每次用其中一个子集当作验证集,剩下的n_splits-1个作为训练集,进行n_splits次训练和…

    2026年1月29日
    5
  • 如何用纯 CSS 创作条形图,不用任何图表库

    如何用纯 CSS 创作条形图,不用任何图表库

    2021年6月16日
    98
  • npm下载和使用(超详细)

    npm下载和使用(超详细)NPM(NodePackageManager)简称为Node包管理工具安装(首先我们需要安装Node)Mac如果没有安装Node可以使用mac的包管理神器HomeBrew进行安装,首先下载HomeBrew,接下来在终端执行以下命令brewinstallnode也可以选择去官网下载pkg安装包,记得下载长期稳定版,即LTS版windows可以在官网中选择windows相对应的版本,同样下载稳定版本,一步点击安装即可使用当下载好Node后我们就可以使用n..

    2025年7月10日
    6
  • MyEclipse8.5免费的注册码[通俗易懂]

    MyEclipse8.5免费的注册码[通俗易懂]打开MyEclipse8.5,点击工具栏上的”MyEclipse”菜单–》SubscriptionInformation–》填入Subscribe和SubscriptionCode,如下:这三个,MyEclipse8.5注册码,到2017年   (1)Subscriber:jom   SubscriptionCode:wLR8ZC-855575-625668535

    2026年4月19日
    4
  • keySet和entrySet

    keySet和entrySetkeySet 是键的集合 Set 里面的类型即 key 的类型 entrySet 是键 值对的集合 Set 里面的类型是 Map Entry 使用 entrySet 则必须将 map 对象转换为 Map Entry keySet 则不需要 KeySet 将 Map 中所有的键存入到 set 集合中 因为 set 具备迭代器 所有可以迭代方式取出所有的键 通过 e get key 方法取值 entrySet S

    2026年3月18日
    2

发表回复

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

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