Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Stream a file to a socket.io client.

branch: master

Initial commit.

latest commit fb58f5a5c3
Mikeal Rogers authored February 27, 2012
Octocat-spinner-32 README.mkd Initial commit. February 27, 2012
Octocat-spinner-32 client.js Initial commit. February 27, 2012
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
Octocat-spinner-32 test.html Initial commit. February 27, 2012
README.mkd

siofile - read files over socket.io

server

  var siofile = require('siofile')

  io.sockets.on('connection', function (socket) {
    socket.on('siofile', siofile(socket))
  })

This is incredibly insecure because it allows all clients access to your entire filesystem.

Instead.

  socket.on('siofile', siofile(socket, '/home/me/myfile'))

Or you can give a list of files you want to make available.

  socket.on('siofile', siofile(socket, ['/home/me/myfile1', '/home/me/myfile2']))

browser

  <script src="/socket.io/socket.io.js"></script>
  <script>
    var socket = io.connect('http://localhost')

    socket.on('connect', function () {
      siofile(socket).read('/home/me/myfile', function (err, data) {
        console.log(err, data)
      })
    })

  </script>

Alternatively, you can also watch a file, which will first read the contents and then call your callback again every time new data is appended to the file. This is ideal for watching log files.

  siofile(socket).watch('/home/me/myfile', function (err, data) {
    console.log(err, data)
  })
Something went wrong with that request. Please try again.