在CommonFilter 增加GZIP压缩总是不完整
但用如下代码,压缩后的网页总是不完整,不管把Close();放到什么位置一样不完整。使用GZipOutputStream也是一样不完整。如果要是写到外面不保存成文件一切正常。如:
// context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
// context.Response.AppendHeader("Content-Encoding", "gzip");
context.Response.Filter = new CommonFilter(context.Response.Filter, stream);
public class CommonFilter : Stream
{
private readonly Stream _responseStream;
private readonly FileStream _cacheStream;
public override bool CanRead
{
get
{
return false;
}
}
public override bool CanSeek
{
get
{
return false;
}
}
public override bool CanWrite
{
get
{
return _responseStream.CanWrite;
}
}
public override long Length
{
get
{
throw new NotSupportedException();
}
}
public override long Position
{
get
{
throw new NotSupportedException();
}
set
{
throw
new NotSupportedException();
}
}
public CommonFilter(Stream responseStream, FileStream stream)
{
_responseStream = responseStream;
_cacheStream = stream;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void SetLength(long length)
{
throw new NotSupportedException();
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
public override void Flush()
{
_responseStream.Flush();
_cacheStream.Flush();
}
public override void Write(byte[] buffer, int offset, int count)
{
using (MemoryStream msTemp = new MemoryStream(count))
{
using (GZipStream gz = new GZipStream(msTemp, CompressionMode.Compress, true))
{
gz.Write(buffer,offset, count);
gz.Close();
buffer = msTemp.ToArray();
count=(int)msTemp.Length;
}
}
_cacheStream.Write(buffer, offset,count);
_responseStream.Write(buffer, offset,count);
}
public override void Close()
{
_responseStream.Close();
_cacheStream.Close();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_responseStream.Dispose();
_cacheStream.Dispose();
}
}
} 相关推荐
科技中介服务机构如何利用平台提升服务效率并拓展客户群体?.docx
科技中介服务机构如何利用平台提升服务效率并拓展客户群体?
科技中介服务机构如何利用数智工具提升技术供需对接的效率?.docx
科技中介服务机构如何利用数智工具提升技术供需对接的效率?
固定电容器可控晶闸管无功补偿装置 (FCTCR)(simulink仿真实现)
内容概要:本文详细介绍了固定电容器可控晶闸管无功补偿装置(FCTCR)的Simulink仿真实现方法,系统阐述了其在电力系统中进行动态无功功率补偿的工作原理与技术特性。通过构建完整的FCTCR仿真模型,深入剖析了装置的系统结构、关键参数配置及建模流程,并重点研究了晶闸管触发角控制策略对无功输出的调节机制,展现了该装置在改善电压稳定性、提升功率因数方面的优良性能。仿真结果有效验证了FCTCR在不同工况下的动态响应能力和控制精度,充分体现了其在现代电力系统无功补偿工程应用中的灵活性与实用性。; 适合人群:具备电力系统分析、电力电子技术基础以及Simulink仿真操作经验的电气工程及相关专业的高年级本科生、研究生,以及从事无功补偿装置研发、电力系统规划与运行的工程技术人员。; 使用场景及目标:①应用于高等院校和科研机构,作为电力系统自动化、柔性交流输电技术等相关课程的教学案例与科研实验平台;②为电力系统中动态无功补偿装置的设计、选型与性能评估提供有效的仿真验证工具;③帮助研究人员和工程师深入理解FCTCR的内部运行机理与控制逻辑,为实际工程项目中的技术方案论证、控制策略优化及系统稳定性分析提供理论依据和技术支持。; 阅读建议:建议读者在阅读过程中,结合Simulink软件动手复现文中所述的仿真模型,严格按照提供的参数进行设置,并通过改变晶闸管的触发角来观察系统电压、电流及无功功率的动态变化,从而深刻掌握控制策略与系统响应之间的内在联系。为进一步深化理解,可尝试在模型中加入不同的负载扰动或故障条件,研究FCTCR的鲁棒性和适应性。
Delphi 13.2控件之SaView.exe
Delphi 13.2控件之SaView.exe
Anatomy动画和大屏
wheresryan22/anatomy 提供的技术仿真,Anatomy动画和大屏实现



