ASP Packaging Class

Source: Internet
Author: User
Tags file size net pack rar split unpack
Packaged

<%
On Error Resume Next
Dim R
Set r = New Rar

R.add Server.MapPath ("A.gif")
R.add Server.MapPath ("A.txt")
R.add Server.MapPath ("test")
R.add Server.MapPath ("file.asp")
R.packname = Server.MapPath ("Xxx.dat")
R.pack
R.rootpath = Server.MapPath ("xxx")
R.packname = Server.MapPath ("Xxx.dat")
R.unpack

Response.Write (Err.Description)
Set r = Nothing
%>
<script language= "Vbscript" runat= "Server" >
'-----------------------------------------------------
' Description: ASP Packaging class
' Author: Small Ash (quxiaohui_0@163.com)
' Link: http://asp2004.net http://blog.csdn.net/iuhxq http://bbs.asp2004.net
' Version: 1.0 Beta
' Copyright: This work can be used for free, but please do not remove copyright information
'-----------------------------------------------------
Class Rar
Dim Files,packname,s,s1,s2,rootpath,fso,f,buf
Private Sub Class_Initialize
Randomize
Dim Rannum
Rannum = Int (90000 * Rnd) + 10000
Packname = &month (now), &day (now), &hour (now) &minute (now), &second (now) &ranNum&. asp2004 "

RootPath = Server.MapPath ("./")

Set files = Server. CreateObject ("Scripting.Dictionary")
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")

Set s = server. CreateObject ("ADODB.") Stream "): S.open:s.type = 1
Set S1 = server. CreateObject ("ADODB.") Stream "): S1. Open:s1. Type = 1
Set s2 = server. CreateObject ("ADODB.") Stream "): S2. Open:s2. Type = 2
End Sub

Private Sub Class_Terminate
S.close:set s = Nothing
S1. Close:set S1 = Nothing
S2. Close:set s2 = Nothing

Set FSO = Nothing
End Sub

Public Sub Add (obj)
If FSO. FileExists (obj) Then
Set f = fso. GetFile (obj)
Files. ADD obj,f.size
ElseIf FSO. FolderExists (obj) Then
Files. ADD obj,-1
Set f = fso. GetFolder (obj)
Set FC = F.files
For each F1 in FC
ADD (LCase (F1). Path))
Next
End If
End Sub

Public Sub Pack
Dim Str
A = files. Keys
b = files. Items
For I=0 to Files.count-1
If B (i) >=0 Then
S.loadfromfile (A (i))
BUF = S.read
If not IsNull (BUF) Then S1. Write (BUF)
End If
str = str & B (i) & ">" &replace (A (i), RootPath, "") &vbcrlf
Next
str = CSTR (Right ("000000000" &len (str)) & STR
BUF = Texttostream (str)
s.position = 0
S.write BUF
S1. Position = 0
S.write S1. Read
S.seteos
S.savetofile (Packname)
End Sub

Public Sub Unpack

  if not FSO. FolderExists (rootpath) Then
   fso. CreateFolder (rootpath)
  end If
  dim size
   convert file size
  s. LoadFromFile (packname)
  size = CInt (Streamtotext (s.read))
  str = Streamtotext (S. Read (size))
  arr = Split (STR,VBCRLF)

  for i=0 to Ubound (arr)-1
   arrfile = Split (arr (i), ">")
   if Arrfile (0) < 0 Then
    if not FSO. FolderExists (Rootpath&arrfile (1)) Then
     fso. CreateFolder (Rootpath&arrfile (1))
    end If
   elseif arrFile (0) >= 0 Then
    if FSO. FileExists (Rootpath&arrfile (1)) Then
     fso. DeleteFile (Rootpath&arrfile (1))
    end If
    s1. Position = 0
    buf = s.read (arrfile (0))
    if not IsNull (BUF) Then s1 . Write (BUF)
    s1. SetEOS
    s1. SaveToFile (Rootpath&arrfile (1))
   end If
  next
 end Sub

 public Function Streamtotext (stream)
  if IsNull (stream) Then
    Streamtotext = ""
  else
   set sm = server. CreateObject ("ADODB.") Stream "): Sm. Open:sm. Type = 1
   sm. Write (Stream)
   sm. Position = 0
   sm. Type = 2
   sm.charset = "gb2312"
   sm. Position = 0
   streamtotext = Sm. ReadText ()
   sm. Close:set sm = Nothing
  end If
 end Function

Public Function Texttostream (text)
If text= "" Then
Texttostream = "' What should I write here?" Empty stream?
Else
Set SM = server. CreateObject ("ADODB.") Stream "): Sm. Open:sm. Type = 2:sm.charset = "gb2312"
Sm. WRITETEXT (text)
Sm. Position = 0
Sm. Type = 1
Sm. Position = 0
Texttostream = Sm. Read
Sm. Close:set sm = Nothing
End If
End Function
End Class
</script>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.