日期:2014-01-19  浏览次数:20926 次

在解码速度方面,化境 2.0 已经非常高了,但是,它还存在以下两个问题:
1、用Data_5xsoft.Write  Request.BinaryRead(Request.TotalBytes)一次读取全部数据,以及用RequestData =Data_5xsoft.Read 一次取出全部数据,在上传数据过大时,会由于内存不足,导致上传失败,这里应该采用分段读取方式。
2、保存数据时,需要先从Data_5xsoft中复制到一个临时流中,在保存大文件时,需要两倍的存储资源,在单机状态下测试,可以发现保存时间随文件尺寸急剧增长,甚至超过上传和解码时间。
本人所写的这个类,采用在解码的过程中,逐块读取(注意:块的大小与速度不成正比,单机测试表明,64K的块比1M的块快得多)的方法,解决问题1,同时采用对普通数据,写入工作流;对文件内容,直接写入文件自身的流的方式,解决问题2。
代码如下,用法类似于化境:
Server.ScriptTimeOut = 600
Class QuickUpload
 Private FForm, FFile, Upload_Stream, ConvertStream
 
 property get Form
  set Form = FForm
 end property
  
 property get File
  set File = FFile
 end property
  
 Private Sub Class_Initialize 
  dim iStart, iEnd, boundary, FieldName, FileName, ContentType, ItemValue, theFile, LineEnd
  
  set FForm=CreateObject("Scripting.Dictionary")
  set FFile=CreateObject("Scripting.Dictionary")
  set Upload_Stream=CreateObject("Adodb.Stream")
  Upload_Stream.mode=3
  Upload_Stream.type=1
  Upload_Stream.open
  set ConvertStream = Server.CreateObject("adodb.stream")
  ConvertStream.Mode =3
  ConvertStream.Charset="GB2312"
  
  if Request.TotalBytes<1 then Exit Sub
    
  ’dStart = CDbl(Time)
  
  ’查找第一个边界
  iStart = Search(Upload_Stream, ChrB(13)&ChrB(10), 1)
  ’取边界串
  boundary = subString(1, iStart-1, false)
  ’不是结束边界,则循环
  do while StrComp(subString(iStart, 2, false),ChrB(13)&ChrB(10))=0
   iStart = iStart+2
   ’取表单项信息头
   do while true
    iEnd = Search(Upload_Stream, ChrB(13)&ChrB(10), iStart)
    ’分解信息头
    line = subString(iStart, iEnd-iStart, true)
    ’移动位置
    iStart = iEnd+2
    if Line="" then Exit do
    pos = instr(line,":")
    if pos>0 then
     if StrComp(left(Line,pos-1),"Content-Disposition",1)=0 then
      ’取表单项名称
      FieldName = ExtractValue(Line,pos+1,"name")
      ’取文件名称
      FileName = ExtractValue(Line,pos+1,"filename")
      ’删除文件路径
      FileName = Mid(FileName,InStrRev(FileName, "\")+1)
     elseif StrComp(left(Line,pos-1),"Content-Type",1)=0 then
      ’取文件类型
      ContentType = trim(mid(Line,pos+1))
     end if
    end if
   loop
   ’取表单项内容
   if FileName<>"" then
    ’新建文件内容
    set theFile = new FileInfo
    theFile.Init FileName, ContentType