Examples of [File Split] and [File Merge] code written by binary operation classes: <% DIM OBJSET OBJ = New FileClass' Dividing DIM IOBJ.OpenFile "g: /2.mp3", "" i = 0do while Not obj.eof if obj.newfile ("G: / 2 _" & I & I ". MP3", OBJ.READ (2048 * 1024) The 'Separated into 2M Size file response.write "Divided into file G: / 2_" & I & ". MP3 success!
"Else Response.write" divided into file G: / 2 _ "& I &". MP3 failed!
"END I = i 1Loopobj.closefile
'Merger Document DIM Jobj.Appendfile "g: /2_0.mp3", "g: /2_1.mp3", "g: / mp3.mp3" for j = 2 to i-1 obj.appendfile "g: / mp3. MP3 "," G: / 2 _ "& J &" "" NEXTRESPONSE.WRITE "merge file successfully!" set obj = nothing%> Class code: <% '/ ********* ******************** Binary operation class ********************************** *********** '/ * author: dead in the water fish (dead)' / * date: September 7, 2004 '/ * BLOG: http://blog.9cbs.net / bpfish '/ *' / * Usage: '/ * DIM OBJ, SDATA, IPOS, ISIZE' / * SET OBJ = New FileClass' / * Obj.openFile "File absolute path address", "Open mode" Opens file, Open mode and the same value of the same '/ * open mode of AdoDB.Stream's Mode property: 1 = Read 2 = write 3 or null value = read and write' /*obj.appendto "[additional files] Absolute Path Address "'Putting the currently open file to the end of the [Additional File]' /*obj.move value 'relative to the currently open file pointer [value] one byte' /*obj.moveto value 'put the current The open file pointer is absolutely for the file header [value] one byte '/*sdata =obj.read (value)' / * 'Description: obj.read (value) reads the currently opened file [value] Section '/ * Note: The read position is related to the file pointer, if the value is 0, start reading data from the current file location until the file end' /*data =obj.readall 'reads the currently open file all data' / * IPOS = Obj.position 'Returns the file pointer position of the current file (position attribute is read-only, can not be written)' / * isize = obj.size 'Returns the size of the current file, name the total number of bytes' / * if obj.eof the response.write "file end"' / * Note: Obj.eof is the end of the file pointer to the end of the file, when Obj.eof = True '/ * Obj.position = Obj.size.
But obj.position = obj.size does not necessarily obj.eof = true '/ * obj.saves "Save As File Name", "Save Mode"' Saves the currently opened file as a new file, and the value of the save mode is 1 Or 2 1 = Non-overlay 2 = Override '/*obj.closefile' Close the currently open file '/*obj.newfile "New File Name", byte Data Stream' Create a new file, If the file exists, it will overwrite. If the non-byte data flows, the new file failed '/*obj.Appendfile "file 1", "file 2", "Generate file"' / * 'will [file 1] and [file 2 ] Combined into a new [generated file], if [Generate File] exists, the merge failed! If [Generate File] is set, [File 2] is incorporated into [File 1. '/*Response.write obj.gettext' converts [byte data stream] into a string and returns' / * set obj = nothing '/ *' / * Description: byte data stream is binary Data '/ * The following method can not need to first openfile: newfile and appendfile and gettext methods, otherwise you must use the OpenFile method to open file' / **************** *********************************************************** *************** Class FileClassPrivate ObjStream 'AdoDb.Stream Object Variable Private OpenFlag' Have Opened File Private fileiseOf '/ ************ *********************************************************** ******************* '/ * function name: initialization class' / ******************** *********************************************************** *********** Private Sub Class_Initialize OpenFlag = False FileIsEof = TrueEnd Sub '/ *************************** *********************************************************** *****'/* Function name:'/************************************* **************************************************************** Private Sub Class_Terminate Call Closefile Set objstream = Nothingend Sub
'/ ********************************************************** ************************************* * Function Name: Get the size of the file (-1 = no open document)'/********************************************* ******************************************************* Public property get size if openflag dam1 = objstream.size else SIZE = -1 End ifend property '/ ************************************************** ***************************************** / * function name: get the current file File pointer position (-1 = no open file) '/ ****************************************** ******************************************* Public Property Get Position if openflag kiln position = objstream.position else position = -1 End imp / -1 End imp
'/ ********************************************************** ********************************** / * function name: get the current file is in the file (True = File Tail False = No) '/ * Note: The file is just at the last byte when returning to true, returning to true because the tail of the trick moved pointer to the file (size)' / * If the external call When this value is recommended, when the value is True, stop any read data operation, otherwise there may be data to return '/ ********************** *********************************************************** ********** PUBLIC Property Get EOF EOF = fileiseofend property '/ ***************************************** *********************************************************** ** '/ * function name: Open file' / * Parameters: filename = The file name to open, absolute address '/ * OpenMode = Open the mode value of the file is the same as the mode property of the AdoDb.Recordset object' / *** *********************************************************** **************************** Public Function OpenFile (Byval FileName, BYVAL OPENMODE) ON Error Resume Nextdim SfileName, Imode IF OpenFlag Then ' If you have opened a file, turn off the previous file call closefile end if sfilename = trim (filename) if sfilename = "" "" If IF = false exit function endiffe = cint (openmode) 'If you enter Do not It is a number of default 3 open mode (read-written type) if err.number <> 0 Then Imode = 3 Err.clear end if IF = 3 Err.clear End IF IF IFE <> 0 and Imode <> 1 and Imode <> 2 and Imode <> 3 And Imode <> 4 and Imode <> 8 and Imode <> 12 and Imode <> 16 and Imode <> 4194304 Then IMODE = 3 'If the input number is not accepted by the value of AdoDb.ReadStream's Mode property, the default value is used 3 Endiff 'on Error Goto 0 if not initobjstream life' Initialization object, if you can't initialize, return a false value fileiseof = true openflag = false openfile =
False Exit Function End If ObjStream.Type = 1 ObjStream.Mode = iMode ObjStream.Open ObjStream.LoadFromFile sFileName If Err.Number <> 0 Then Err.Clear Exit Function End If FileIsEof = False OpenFlag = True OpenFile = TrueEnd Function '/ * *********************************************************** ********************************** * Function Name: Read the binary content of the specified length '/ * parameters: Numbytes = Number to read (NumBytes = 0 Numbytes = 0 All content after the current file pointer) '/ * returns: read byte data' / *************** *********************************************************** **************** PUBLIC FUNCTION READ (BYVAL NUMBYTES) DIM INUM IF NOTETEG1EE EXIT FUNCTION INUM = FileiseOf = False IF = FALSE IF iNum <0 Then Exit Function ElseIf (iNum ObjStream.Position)> ObjStream.Size Then 'iNum = ObjStream.Size-ObjStream.Position FileIsEof = True End If If iNum = 0 Then Read = ObjStream.Read Else Read = ObjStream.Read (inum) end ifend function
'/ ********************************************************** *********************************** / * function name: read all content '/ * parameters : '/ * Back: All byte data for reading the file' / ******************************************** *************************************************************************** PUBLIC FUNCTION Readall if not openflag dam.position = 0 readall = objstream.read fileiseof = TrueEnd Function
'/ ********************************************************** ******************************************** / * function name: file saved as' / * parameter: filename = Save As File Absolute Path Options = Save Save As mode (1 = Non-overlay 2 = overwrite) '/ * Return: All byte data of the file' / ************** *********************************************************** ***************** Public Function Saveas (Byval FileName, Byval Options) on Error ResMe nextddim sfilename, IOption if not openflag the saveness = false exit function end if sfilename = trim FileName) if sfilename = "" "" = false exit function end if IOption = cint (options) if err.Number <> 0 THEN 'If non-numeric data, the default value 1 = non-overlay mode Save = 1 ERR .Clear end if if Ioption <> 1 and IOPTION <> 2 THEN 'If the value of Options is not in the range of 1 and 2, the default value is used 1 IOption = 1 end if objstream.savetofile sfilename, IOption if err.number <> 0 Then Err.clear saveas = false exit function end if saveas = truend function
'/ ********************************************************** ********************************** The / * function name: append file data to another file '/ * Parameters: filename = The appended file absolute path '/ * Return: true = Additional Data Success FALSE = Additional File Data Failed' / ********************************* *********************************************************** ********** Public Function AppendTo (ByVal FileName) On Error Resume NextDim sFileName, AppendObj If Not OpenFlag Then AppendTo = False Exit Function End If sFileName = Trim (FileName) If sFileName = "" Then AppendTo = False Exit Function End If 'open the file to be added Set AppendObj = Server.CreateObject ( "ADODB.Stream") AppendObj.Type = 1 AppendObj.Mode = 3 AppendObj.Open AppendObj.LoadFromFile sFileName If Err.Number <> 0 Then Err .Clear appendto = false exit function end if appendobj.position = appendobj.size 'Move pointer to file end appendobj.write readall' data AppendObj.savetofile sfilename, 2 'Save As IF Err.NUMBER < > 0 Then Err.clear appendto = false exit function e Nd if appendobj.close set appendobj = Nothing appendto = trueEnd function
'/ ********************************************************** ****************************************** Function Name: Save SDATA data as a file '/ * parameter : Filename = The appended file absolute path '/ * Return: true = Additional data success false = additional file data failed' / *********************** *********************************************************** ********* Public Function NewFile (ByVal FileName, ByRef sData) On Error Resume NextDim sFileName, AppendObj sFileName = Trim (FileName) If sFileName = "" Then NewFile = False Exit Function End If 'is added to opening file Set AppendObj = Server.CreateObject ( "ADODB.Stream") AppendObj.Type = 1 AppendObj.Mode = 3 AppendObj.Open If Err.Number <> 0 Then Err.Clear NewFile = False Exit Function End If If Left (TypeName (SDATA), 4) = "Byte" THEN 'is byte stream data to add Appendobj.write sdata' to add data the first file of the first file appendobj.savetofile sfilename, 2 'Save As 自己 自己 自己 = false exit function endiff IF err.number <> 0 Then Err.clear newfile = false exit function end if appendobj.clo SE set appendobj = Nothing newfile = truend function
'/ ********************************************************** *********************************** / * function name: file merger '/ * parameter: appendfilename = merge File 1 sourceFileName = Merge file 2 TargetFileName = After the merged file (if empty, save as the first file name) '/ * Return: true = Merge success FALSE = merge failed' / ******** *********************************************************** ************************ Public Function appendFile (ByVal appendFileName, ByVal SourceFileName, ByVal TargetFileName) On Error Resume NextDim sFileName1, sFileName2, sFileName1 AppendObj1, AppendObj2Dim sTargetFile = Trim (appendFileName) sFileName2 = Trim (SourceFileName) sTargetFile = Trim (TargetFileName) If sFileName1 = "" Or sFileName2 = "" Then appendFile = False Exit Function End If 'open to be added and additional documents Set AppendObj1 = Server.CreateObject ( "ADODB.Stream") Set AppendObj2 = Server.CreateObject ( "ADODB.Stream") AppendObj1.Type = 1 AppendObj1.Mode = 3 AppendObj1.Open AppendObj1.LoadFromFile sFileName1 AppendObj2.Type = 1 AppendObj2.Mode = 3 AppendObj2.Open Appendobj2.low FromFile sFileName2 If Err.Number <> 0 Then Err.Clear AppendFile = data If sTargetFile False Exit Function End If AppendObj1.Position = AppendObj1.Size 'to move the pointer to the end of the file AppendObj1.Write AppendObj2.Read' append data of the first file = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" End if appendobj1.close set appendobj1 =
Nothing appendobj2.close set appendidobj2 = nothing appendfile = truend function '/ ***************************************************** ******************************************************* / * function Name: Mobile file pointer (relative mobile) '/ * parameter: tonum = number of bytes to move' / * '/ ********************** *********************************************************** ********* PUBLIC SUB MOVE (BYVAL TONUM) DIM INUM IF NOTENTEG1 EXIT SUB IF ISINTEGER (TONUM) THEN EXIT SUB INUM = ObjStream.position Clng (Tonum) fileiseof = false if inum <0 THEN inum = 0 elseif inum> objstream.size kiln = objstream.size fileiseof = true end if objstream.position = inumend SUB
'/ ********************************************************** ************************************** * Function Name: Mobile file pointer (absolutely mobile) '/ * Parameters: tonum = number of bytes to move '/ *' / ***************************************************** ***************************************************** Public SUB MOVETO (ByVal ToNum) Dim iNum If Not OpenFlag Then Exit Sub If Not IsInteger (ToNum) Then Exit Sub iNum = Clng (ToNum) FileIsEof = False If iNum <0 Then iNum = 0 ElseIf iNum> ObjStream.Size Then iNum = ObjStream.Size Fileiseof = true end inument subsection = inumend SUB
'/ ********************************************************** ********************************** / * function name: close the open file '/ *** *********************************************************** ********************************************** Public Sub Closefileon Error Resume Next if not isnothing (Objstream) Then objstream.close end if openflag = false Fileiseof = trueend sub
'/ ********************************************************** ********************************** / * function name: initialization Objstream object '/ ***** *********************************************************** ******************************************** Private function init init in = server.createObject ("adoDb.stream) .createObject (" AdoDb.Stream). ") If err.number <> 0 Then Err.clear initobjstream = false exit function end if end if initobjstream = true = truend function '/ ****************************** *********************************************************** ********** '/ * Function Name: Get binary conversion to string data' / ********************************* *********************************************************** ******** Public Function GetText (Byref Vin) On Error ResMe nextddim Strreturn, I, thischarcode, Nextcharcode Strreturn = "" for i = 1 to lenb (vin) thischarcode = ASCB (MIDB (Vin, i, 1 )) IF thischarcode <& h80 kilocode = strreturn & chr (thischarcode) Else Ne Xtcharcode = ASCB (MIDB (VIN, I 1, 1)) Strreturn = Strreturn & Chr (Clng (thischarcode) * & H100 CINT (Nextcharcode)) i = i 1 end if next gettext = strreturnend function
'/ ********************************************************** ************************************* * Function Name: Determine whether the OBJ object is null '/ * *********************************************************** ********************************************************************** Private Function isnothing (obj) if not isobject (obj) Then isnothing = true exit function end If IF INULL (OBJ) THEN INTHING = true exit function end if isnothing = falseend function '/ ************************************************************************************************************************************************************** *********************************************************** ************** '/ * Function Name: Judgment is a digital value (0, 1, 2, 3, 4, 5 ........... 9) '/ ********************************************************** ***************************************************** Private Function ISINTEGER (PARA) ON Error Resume Next Dim Str Dim L, I If ISNULL (PARA) THENTEGER = false exit function end if str = cstr (para) if Trim (str) = "" "" = 1 = false exit function end if L = LEN (STR) for i = 1 to L IF MID (STR, I, 1)> "9" OR MID (STR, I, 1) <"0" THENTEGER = FALSE EXIT function end if next isinteger = true if err.number <> 0 Then Err.clerend functionend Class%>