惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
小众软件
小众软件
S
Schneier on Security
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
博客园_首页
S
Security Affairs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - Franky
C
Check Point Blog
GbyAI
GbyAI
H
Help Net Security
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
博客园 - 叶小钗
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
C
Cybersecurity and Infrastructure Security Agency CISA
SecWiki News
SecWiki News
T
Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
H
Hacker News: Front Page
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
Google Online Security Blog
Google Online Security Blog
P
Privacy & Cybersecurity Law Blog
N
News | PayPal Newsroom
M
MIT News - Artificial intelligence
P
Privacy International News Feed
博客园 - 三生石上(FineUI控件)
美团技术团队
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
Last Week in AI
Last Week in AI
Spread Privacy
Spread Privacy
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
Engineering at Meta
Engineering at Meta

博客园 - LDAR泄漏检测与修复

LDAR检测-新型造假套路是低价竞争造成的造假吗?高价的它也造假,造假本质是利益驱动的,和价格关系不大-没有严格的监管造假不会停 LDAR管理系统-检测APP解决方案 成立LDAR检测公司的条件和投资额度(扩项)-泄漏检测与修复CMA认证 LDAR检测设备,租设备送设备,以租待购便携式VOCs总烃分析仪 LDAR检测设备维修及以旧换新便携式VOCs总烃分析仪 3万元一台,LDAR便携式VOCs总烃分析仪,关注公众享优惠活动价格,转发享更多优惠! LDAR(泄漏检测与修复)如何快速准确建档 泄漏检测(LDAR)在建档和检测过程中造假套路和不规范行为汇总 LDAR泄漏检测与修复过管理系统 泄漏检测与修复(LDAR)信息管理平台 泄漏检测与修复(LDAR)综合管理系统 LDAR泄漏检测与修复过程管控平台 泄漏检测与修复(LDAR)过程管控平台(销售出租)VOCs便携式总烃分析仪(销售出租) LDAR市场存在问及解决方案 (LDAR)挥发性挥发性有机物泄漏检测与修复管理系统解决目前市场存在的问题 Mysql遇到的问题总结 权限管理和信息化系统快速开发框架源码学学习总结 通用权限系统框架功能实现设计 系统架构设计
使用GZipStream实现压缩和解压缩
LDAR泄漏检测与修复 · 2022-01-03 · via 博客园 - LDAR泄漏检测与修复

概述

之前做项目,涉及到存入到数据库或者http传输的数据量比较大,这个时候,就需要考虑在存入数据库或者发送传输之前,将数据压缩下,当从数据库中取出时,再解压还原数据。特地找了下发现有GZipStream可以实现这个功能。此类表示gzip数据格式,该格式使用行业标准算法进行无损文件压缩和解压缩。该格式包括用于检测数据损坏的循环冗余校验值。gzip数据格式使用与DeflateStream类相同的算法,但可以扩展为使用其他压缩格式。该格式很容易以专利未涵盖的方式实施。从.NET Framework 4.5开始,DeflateStream类使用zlib库进行压缩。因此,与.NET Framework的早期版本相比,它提供了更好的压缩算法,并且在大多数情况下,提供了较小的压缩文件。

GZipStream使用的一般流程如下:

打开一个现有的文件

打开/创建输出文件

创建GZipStream对象

逐字节读源文件,并把它传递到GZipStream

使用GZipStream写入到输出文件流

代码实现

1、压缩字符串

         /// <summary>
        /// 壓縮字串,回傳 Base64 結果
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string ZipText(string text)
        {
            byte[] inputBytes = Encoding.UTF8.GetBytes(text);
            return ZipText(inputBytes);
        }

        public static string ZipText(byte[] inputBytes)
        {
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (GZipStream gs = new GZipStream(outputStream, CompressionMode.Compress))
                {
                    gs.Write(inputBytes, 0, inputBytes.Length);
                }

                byte[] outputBytes = outputStream.ToArray();
                string result = Convert.ToBase64String(outputBytes);
                return result;
            }
        }

2、解压缩字符串

        /// <summary>
        /// 解壓縮字串
        /// </summary>
        /// <param name="zippedText"></param>
        /// <returns></returns>
        public static string UnzipZippedText(string zippedText)
        {
            if (String.IsNullOrEmpty(zippedText))
            {
                return String.Empty;
            }
            string unzipedText = null;
            try
            {
                byte[] buffer = Convert.FromBase64String(zippedText);
                MemoryStream ms = new MemoryStream(buffer);
                GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress);

                using (StreamReader streamReader = new StreamReader(zipStream))
                {
                    unzipedText = streamReader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                unzipedText = String.Empty;
            }

            return unzipedText;
        }

来源    使用GZipStream实现压缩和解压缩 (qq.com)