Skip to content

Instantly share code, notes, and snippets.

@geta6
Created July 8, 2013 04:30
Show Gist options
  • Save geta6/5946233 to your computer and use it in GitHub Desktop.
Save geta6/5946233 to your computer and use it in GitHub Desktop.
こんなイメージ
Stream = require 'stream'
class Writable extends Stream.Writable
constructor: (@socket, options = {}) ->
super options
write: (chunk, encoding, callback) ->
@socket.emit 'data', chunk.toString(encoding)
end: (chunk, encoding, callback) ->
@socket.emit 'data', chunk.toString(encoding) if chunk
@socket.emit 'end'
io.sockets.on 'connection', (socket) ->
stream = fs.createReadStream 'package.json'
stream.pipe new Writable socket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment