muduo之GzipFile
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相关推荐
- muduo 与 boost asio 吞吐量对比
muduo (http://code.google.com/p/muduo) 是一个基于 Reactor 模式的 C++ 网络库,我在编写它的时候并没有以高并发高吞吐为主要目标,但出乎我的意料,pin ...
- muduo之Logger
Logger用来记录和分析日志. Logging.h // Use of this source code is governed by a BSD-style license // that can ...
- muduo之Atomic
Atomic是muduo原子操作的实现类. Atomic.h // Use of this source code is governed by a BSD-style license // that ...
- muduo之Singleton
muduo中的单例模式 Singleton.h // Use of this source code is governed by a BSD-style license // that can be ...
- muduo之CountDownLatch.cc
CountDownLatch用线程同步的. CountDownLatch.h // Use of this source code is governed by a BSD-style license ...
- muduo之ThreadPool
muduo中的线程池. ThreadPool.h // Use of this source code is governed by a BSD-style license // that can b ...
- muduo之Thread
muduo也对线程进行了封装,下面看一下实现. Thread.h // Use of this source code is governed by a BSD-style license // th ...
- muduo之ThreadLocal
ThreadLocal用来存储线程私有数据的类. // Use of this source code is governed by a BSD-style license // that can b ...
- muduo之mutex和condition
线程同步所需的mutex和condition,记录一下. Mutex.h // Use of this source code is governed by a BSD-style license / ...
最新文章
- centos下使用mysql,centos下使用mysql的一些问题和解决方法
- CUDA系列学习(一)An Introduction to GPU and CUDA
- 如何上传html验证文件大小,html5 实现客户端验证上传文件的大小(简单实例)
- 【Python自然语言处理】中文分词技术——规则分词
- 大数据面试-02-大数据工程师面试题
- h5 客服系统源码_Bos:做在线客服系统项目(附源码)
- IntelliJ Idea学习笔记008---Idea左侧栏不显示目录结构_或者只显示一个Project不显示其他东西
- C++ ------------------------- 文件的复制
- 缓存与缓冲的区别 Difference Between Cache and Buffer
- html给td内容加删除线,【原创】tr上加删除线-且满足一个页面多表格
- 网页前端设计一般思路
- MPB:南农韦中组-​根系分泌物调控土壤微生物群落结构和功能的研究方法
- Photoshop照片模糊变清晰大全
- N个鸡蛋放到M个篮子中
- mysql空洞,mysql crud造成数据空洞的原因
- 2021:Check it again:Progressive Visual Question Answering via Visual Entailment通过视觉暗示进行渐进式视觉问答
- 自学Java如何正确入门?
- 软件开发工期估算系列(5)——規模見積もりの王様「LOC見積もり」 ~見積もりの基本技法 その2
- Ios常用第三方框架(一)
- Python3之旅之计算机基础知识
热门文章
- 服务 TCP 断线错误分析
- 正向代理反向代理 简(fu)明(za)解释
- codeblock 恢复默认字体设置
- 201521123111《Java程序设计》第14周学习总结
- 网站真分页js代码该怎么写? 1
- PowerDesigner 小工具窗
- WIN server 2003 下无法安装adobe cs3 终极解决方法。
- DOSBOX使用的一些方法和注意点(汇编实验中遇到的)
- C++中的变量不初始化是什么结果?(整型、bool型、字符型)结果都是随机的,不确定
- CCF-CSP 201703-2 试题名称:	学生排队(满分代码)