Skip to content

Instantly share code, notes, and snippets.

@manveru
Created June 28, 2010 04:33
Show Gist options
  • Save manveru/455452 to your computer and use it in GitHub Desktop.
Save manveru/455452 to your computer and use it in GitHub Desktop.
router.post('/save').
bind (req, res, next) ->
chunks: []
req.addListener 'data', (chunk) ->
chunks.push chunk
req.addListener 'end', ->
totalLength: chunks.reduce (sum, chunk) ->
sum + chunk.length
, 0
p totalLength
body: new Buffer(totalLength)
offset: 0
for chunk in chunks
length: chunk.length
chunk.copy body, offset, 0, length
offset += length
p body.toString('ascii')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment