Reading a binary file in chunks...

Reply

Join Date: Jul 2009
Posts: 1
Reputation: bobjonson4 is an unknown quantity at this point 
Solved Threads: 0
bobjonson4 bobjonson4 is offline Offline
Newbie Poster

Reading a binary file in chunks...

 
0
  #1
Jul 7th, 2009
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!

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim objFSO As New FileSystemObject
  2. Dim filePath As String
  3.  
  4. filePath = "C:\filename here"
  5.  
  6. If (objFSO.FileExists(filePath)) Then
  7. Set objFSO = Nothing
  8.  
  9. Dim iFileNum As Integer
  10. Dim lBytesLeft As Long
  11. Dim B() As Byte
  12.  
  13. iFileNum = FreeFile
  14. ReDim B(BUFF_SIZE - 1)
  15.  
  16. Open filePath For Binary As iFileNum
  17.  
  18. response.Buffer = True
  19. response.AddHeader "Content-Length", LOF(iFileNum)
  20.  
  21. response.ContentType = "application/octet-stream"
  22.  
  23. lBytesLeft = LOF(iFileNum)
  24.  
  25. If (response.IsClientConnected) Then
  26. Do While (lBytesLeft > 0)
  27. If (lBytesLeft < BUFF_SIZE) Then
  28. ReDim B(lBytesLeft - 1)
  29. End If
  30.  
  31. Get #iFileNum, , B()
  32.  
  33. response.BinaryWrite B
  34. response.Flush
  35. Sleep 0.55
  36.  
  37. lBytesLeft = lBytesLeft - BUFF_SIZE
  38. Loop
  39. Else
  40. response.End
  41. End If
  42.  
  43. Close iFileNum
  44. end if

Thank you very much for any help at all.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC