<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>大文件下载 &#8211; Simon</title>
	<atom:link href="https://www.luisimon.com/tag/%E5%A4%A7%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.luisimon.com</link>
	<description>blog</description>
	<lastBuildDate>Mon, 26 Apr 2021 07:58:52 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://www.luisimon.com/wp-content/uploads/2019/09/cbrks-x5t4i-001.ico</url>
	<title>大文件下载 &#8211; Simon</title>
	<link>https://www.luisimon.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>C#大文件分块下载</title>
		<link>https://www.luisimon.com/2020/12/27/405/</link>
		
		<dc:creator><![CDATA[Simon]]></dc:creator>
		<pubDate>Sun, 27 Dec 2020 13:01:32 +0000</pubDate>
				<category><![CDATA[編程三兩事]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[大文件下载]]></category>
		<category><![CDATA[流]]></category>
		<guid isPermaLink="false">https://www.luisimon.xyz/?p=405</guid>

					<description><![CDATA[C#文件(大文件)分塊下載]]></description>
										<content:encoded><![CDATA[
<p><em>当我们要想要将一个大文件推给(http)客户端时,由于文件太大我们需要分块传输,下面举例说明</em></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
using (var ms = new MemeryStream())
{
	//100K 每次读取文件，只读取100K，这样可以缓解服务器的压力
	const long ChunkSize = 102400;
	byte&#91;] buffer = new byte&#91;ChunkSize];

	//获取下载的文件总大小
	long dataLengthToRead = ms.Length;
	while (dataLengthToRead &gt; 0 &amp;&amp; Response.IsClientConnected)
	{
		//读取的大小
		int lengthRead = ms.Read(buffer, 0, Convert.ToInt32(ChunkSize));
                //向http流写入数据
		Response.OutputStream.Write(buffer, 0, lengthRead);
		Response.Flush();
		dataLengthToRead = dataLengthToRead - lengthRead;
	}
}
</pre></div>


<p></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
