Skip to content

Instantly share code, notes, and snippets.

@craigyk
Created February 4, 2012 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigyk/1736167 to your computer and use it in GitHub Desktop.
Save craigyk/1736167 to your computer and use it in GitHub Desktop.
http ServerRequest data loss?
app.put '/uploads/:fileid', (request,response) ->
getCachePath (path) -> #... does a bunch of prep
stream = fs.createWriteStream path,
bufferSize: 1024*1024*4
encoding: 'binary'
start: start
flags: if start != 0 then 'r+' else 'w'
stream.on 'close', ->
response.send 202,
'Access-Control-Allow-Origin' : '*'
request.pipe stream
# first chunk of data never gets piped
# as an experiment I tried setting a data handler earlier.
# the following emits a console message that the data is getting received
# so compared to the above, it is getting lost somewhere between
app.put '/uploads/:fileid', (request,response) ->
request.on 'data', (data) ->
console.log 'received:',data.length
getCachePath (path) -> #... does a bunch of prep
stream = fs.createWriteStream path,
bufferSize: 1024*1024*4
encoding: 'binary'
start: start
flags: if start != 0 then 'r+' else 'w'
stream.on 'close', ->
response.send 202,
'Access-Control-Allow-Origin' : '*'
request.pipe stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment