GzipFile封装了gzip的一些API,记录一下

// Use of this source code is governed by a BSD-style license
// that can be found in the License file.
//
// Author: Shuo Chen (chenshuo at chenshuo dot com)#pragma once#include "muduo/base/StringPiece.h"
#include "muduo/base/noncopyable.h"
#include <zlib.h>namespace muduo
{class GzipFile : noncopyable
{public:GzipFile(GzipFile&& rhs) noexcept: file_(rhs.file_){rhs.file_ = NULL;}~GzipFile(){if (file_){::gzclose(file_);}}GzipFile& operator=(GzipFile&& rhs) noexcept{swap(rhs);return *this;}bool valid() const { return file_ != NULL; }void swap(GzipFile& rhs) { std::swap(file_, rhs.file_); }
#if ZLIB_VERNUM >= 0x1240bool setBuffer(int size) { return ::gzbuffer(file_, size) == 0; }
#endif// return the number of uncompressed bytes actually read, 0 for eof, -1 for errorint read(void* buf, int len) { return ::gzread(file_, buf, len); }// return the number of uncompressed bytes actually writtenint write(StringPiece buf) { return ::gzwrite(file_, buf.data(), buf.size()); }// number of uncompressed bytesoff_t tell() const { return ::gztell(file_); }#if ZLIB_VERNUM >= 0x1240// number of compressed bytesoff_t offset() const { return ::gzoffset(file_); }
#endif// int flush(int f) { return ::gzflush(file_, f); }static GzipFile openForRead(StringArg filename){return GzipFile(::gzopen(filename.c_str(), "rbe"));}static GzipFile openForAppend(StringArg filename){return GzipFile(::gzopen(filename.c_str(), "abe"));}static GzipFile openForWriteExclusive(StringArg filename){return GzipFile(::gzopen(filename.c_str(), "wbxe"));}static GzipFile openForWriteTruncate(StringArg filename){return GzipFile(::gzopen(filename.c_str(), "wbe"));}private:explicit GzipFile(gzFile file): file_(file){}gzFile file_;
};}  // namespace muduo

muduo之GzipFile相关推荐

  1. muduo 与 boost asio 吞吐量对比

    muduo (http://code.google.com/p/muduo) 是一个基于 Reactor 模式的 C++ 网络库,我在编写它的时候并没有以高并发高吞吐为主要目标,但出乎我的意料,pin ...

  2. muduo之Logger

    Logger用来记录和分析日志. Logging.h // Use of this source code is governed by a BSD-style license // that can ...

  3. muduo之Atomic

    Atomic是muduo原子操作的实现类. Atomic.h // Use of this source code is governed by a BSD-style license // that ...

  4. muduo之Singleton

    muduo中的单例模式 Singleton.h // Use of this source code is governed by a BSD-style license // that can be ...

  5. muduo之CountDownLatch.cc

    CountDownLatch用线程同步的. CountDownLatch.h // Use of this source code is governed by a BSD-style license ...

  6. muduo之ThreadPool

    muduo中的线程池. ThreadPool.h // Use of this source code is governed by a BSD-style license // that can b ...

  7. muduo之Thread

    muduo也对线程进行了封装,下面看一下实现. Thread.h // Use of this source code is governed by a BSD-style license // th ...

  8. muduo之ThreadLocal

    ThreadLocal用来存储线程私有数据的类. // Use of this source code is governed by a BSD-style license // that can b ...

  9. muduo之mutex和condition

    线程同步所需的mutex和condition,记录一下. Mutex.h // Use of this source code is governed by a BSD-style license / ...

最新文章

  1. centos下使用mysql,centos下使用mysql的一些问题和解决方法
  2. CUDA系列学习(一)An Introduction to GPU and CUDA
  3. 如何上传html验证文件大小,html5 实现客户端验证上传文件的大小(简单实例)
  4. 【Python自然语言处理】中文分词技术——规则分词
  5. 大数据面试-02-大数据工程师面试题
  6. h5 客服系统源码_Bos:做在线客服系统项目(附源码)
  7. IntelliJ Idea学习笔记008---Idea左侧栏不显示目录结构_或者只显示一个Project不显示其他东西
  8. C++ ------------------------- 文件的复制
  9. 缓存与缓冲的区别 Difference Between Cache and Buffer
  10. html给td内容加删除线,【原创】tr上加删除线-且满足一个页面多表格
  11. 网页前端设计一般思路
  12. MPB:南农韦中组-​根系分泌物调控土壤微生物群落结构和功能的研究方法
  13. Photoshop照片模糊变清晰大全
  14. N个鸡蛋放到M个篮子中
  15. mysql空洞,mysql crud造成数据空洞的原因
  16. 2021:Check it again:Progressive Visual Question Answering via Visual Entailment通过视觉暗示进行渐进式视觉问答
  17. 自学Java如何正确入门?
  18. 软件开发工期估算系列(5)——規模見積もりの王様「LOC見積もり」 ~見積もりの基本技法 その2
  19. Ios常用第三方框架(一)
  20. Python3之旅之计算机基础知识

热门文章

  1. 服务 TCP 断线错误分析
  2. 正向代理反向代理 简(fu)明(za)解释
  3. codeblock 恢复默认字体设置
  4. 201521123111《Java程序设计》第14周学习总结
  5. 网站真分页js代码该怎么写? 1
  6. PowerDesigner 小工具窗
  7. WIN server 2003 下无法安装adobe cs3 终极解决方法。
  8. DOSBOX使用的一些方法和注意点(汇编实验中遇到的)
  9. C++中的变量不初始化是什么结果?(整型、bool型、字符型)结果都是随机的,不确定
  10. CCF-CSP 201703-2 试题名称: 学生排队(满分代码)