Hi All,
Got a bit of a problem.
I have a COM Component for an ASP project that reads a binary file from a location on the HDD (could be from 60MB-200MB) and, with the response object found in ASP.DLL, sends the file in chunks of 96kb.
The aim was for me to create code that doesn't load the entire file into memory and then send it. But looking at the memory usage in task manager, it seemingly is loading a lot of data in -- memory usage skyrockets to about the size of the file and gradually reduces until the file is sent.
My question to the experts out there -- could you guys help me or give me some pointers to make this code read the file in "as required"? Like not all at once, only read the chunks when needed and send. Hope that makes sense!
Dim objFSO As New FileSystemObject
Dim filePath As String
filePath = "C:\filename here"
If (objFSO.FileExists(filePath)) Then
Set objFSO = Nothing
Dim iFileNum As Integer
Dim lBytesLeft As Long
Dim B() As Byte
iFileNum = FreeFile
ReDim B(BUFF_SIZE - 1)
Open filePath For Binary As iFileNum
response.Buffer = True
response.AddHeader "Content-Length", LOF(iFileNum)
response.ContentType = "application/octet-stream"
lBytesLeft = LOF(iFileNum)
If (response.IsClientConnected) Then
Do While (lBytesLeft > 0)
If (lBytesLeft < BUFF_SIZE) Then
ReDim B(lBytesLeft - 1)
End If
Get #iFileNum, , B()
response.BinaryWrite B
response.Flush
Sleep 0.55
lBytesLeft = lBytesLeft - BUFF_SIZE
Loop
Else
response.End
End If
Close iFileNum
end if
Thank you very much for any help at all. :)