socket-reader.js 915 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Just get the stats, and then don't do anything.
  2. // You can't really "read" from a socket. You "connect" to it.
  3. // Mostly, this is here so that reading a dir with a socket in it
  4. // doesn't blow up.
  5. module.exports = SocketReader
  6. var inherits = require('inherits')
  7. var Reader = require('./reader.js')
  8. inherits(SocketReader, Reader)
  9. function SocketReader (props) {
  10. var self = this
  11. if (!(self instanceof SocketReader)) {
  12. throw new Error('SocketReader must be called as constructor.')
  13. }
  14. if (!(props.type === 'Socket' && props.Socket)) {
  15. throw new Error('Non-socket type ' + props.type)
  16. }
  17. Reader.call(self, props)
  18. }
  19. SocketReader.prototype._read = function () {
  20. var self = this
  21. if (self._paused) return
  22. // basically just a no-op, since we got all the info we have
  23. // from the _stat method
  24. if (!self._ended) {
  25. self.emit('end')
  26. self.emit('close')
  27. self._ended = true
  28. }
  29. }