title: Sending large files with Spray
body: <p>I know very similar questions have been asked before. But I don't think the solutions I found on google/stackoverflow are suitable for me.</p>
  
  <p>I started to write some web services with Scala/Spray, and it seems the best way to send large files without consuming large amouns of memory is using the stream marshalling. This way Spray will send http chunks. Two questions:</p>
  
  <ol>
  <li><p>Is it possible to send the file without using HTTP chunks and without reading the entire file into memory?</p></li>
  <li><p>AFAIK akka.io only process one write at a time, meaning it can buffer one write until it has been passed on to the O/S kernel in full. Would it be possible to tell Spray, for each HTTP response, the length of the content? Thereafter Spray would ask for new data (through akka messages) untill the entire content length is completed. Eg, I indicate my content length is 100 bytes. Spray sends a message asking for data to my actor, I provide 50 bytes. Once this data is passed on to the O/S, spray sends another message asking for new data. I provide the remaining 50 bytes... the response is completed then.</p></li>
  </ol>