asp教程.net(c#)实现多线程断点续传
stream istream = null;
byte[] buffer = new byte[10240];// 缓冲区块10k bytes :
int length;
long datatoread;
string filepath = @"e:softwaresql server 2000 personal edition.iso";
string filename = system.io.path.getfilename(filepath);
try
{
// 打开文件 istream = new filestream(filepath, filemode.open,fileaccess.read, fileshare.read);
response.clear();
datatoread = istream.length;
long p = 0;
if (request.headers["range"] != null)
{
response.statuscode = 206;
p = long.parse(request.headers["range"].replace("bytes=", "").replace("-", ""));
}
if (p != 0)
{
response.addheader("content-range", "bytes " + p.tostring() + "-" + ((long)(datatoread - 1)).tostring() + "/" + datatoread.tostring());
}
response.addheader("content-length", ((long)(datatoread - p)).tostring());
response.contenttype = "application/octet-stream";
response.addheader("content-disposition", "attachment; filename=" + system.web.httputility.urlencode(request.contentencoding.getbytes(filename)));istream.position = p;
datatoread = datatoread - p;
while (datatoread > 0)
{
if (response.isclientconnected)
{
length = istream.read(buffer, 0, 10240);
response.outputstream.write(buffer, 0, length);
response.flush();buffer = new byte[10240];
datatoread = datatoread - length;
}
else
{
//如果用户断开连接 防止无限循环 datatoread = -1;
}
}
}
catch (exception ex)
{
response.write("error : " + ex.message);
}
finally
{
if (istream != null)
{
istream.close();
}
response.end();
}
}
野比大雄的涅槃 最新版v0.8-625
野比大雄的涅槃是一款非常好玩的从端游移植而来的精品哆啦A梦同
汽车模拟器2内置菜单全车解锁版2024 最新版v1.54.2
汽车模拟器2内置涂装版是游戏的破解版本,在该版本中为玩家提供
快递到了亲内置菜单 安卓版v0.6.2
快递到了亲内置菜单是一款非常好玩的模拟经营类手游,内部有功能
我的世界为时已晚模组整合包 手机版v皮神木马
我的世界为时已晚模组整合包是一款剧情向的恐怖游戏像素风格沙盒
纸牌农庄内购版 v1.12.77
纸牌农庄无限道具版是一款将纸牌与模拟经营相结合的游戏,为玩家