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

推荐订阅源

U
Unit 42
S
Security Affairs
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
有赞技术团队
有赞技术团队
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
C
Cisco Blogs
T
Tor Project blog
The Hacker News
The Hacker News
雷峰网
雷峰网
MyScale Blog
MyScale Blog
博客园 - 司徒正美
AWS News Blog
AWS News Blog
GbyAI
GbyAI
Y
Y Combinator Blog
D
DataBreaches.Net
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
T
Tenable Blog
L
LangChain Blog
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
The Cloudflare Blog
A
About on SuperTechFans
IT之家
IT之家
F
Fortinet All Blogs
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
W
WeLiveSecurity
A
Arctic Wolf
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 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)