UI for Zipcoin Blue

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Basically just a wrapper around an fs.readlink
  2. //
  3. // XXX: Enhance this to support the Link type, by keeping
  4. // a lookup table of {<dev+inode>:<path>}, so that hardlinks
  5. // can be preserved in tarballs.
  6. module.exports = LinkReader
  7. var fs = require('graceful-fs')
  8. var inherits = require('inherits')
  9. var Reader = require('./reader.js')
  10. inherits(LinkReader, Reader)
  11. function LinkReader (props) {
  12. var self = this
  13. if (!(self instanceof LinkReader)) {
  14. throw new Error('LinkReader must be called as constructor.')
  15. }
  16. if (!((props.type === 'Link' && props.Link) ||
  17. (props.type === 'SymbolicLink' && props.SymbolicLink))) {
  18. throw new Error('Non-link type ' + props.type)
  19. }
  20. Reader.call(self, props)
  21. }
  22. // When piping a LinkReader into a LinkWriter, we have to
  23. // already have the linkpath property set, so that has to
  24. // happen *before* the "ready" event, which means we need to
  25. // override the _stat method.
  26. LinkReader.prototype._stat = function (currentStat) {
  27. var self = this
  28. fs.readlink(self._path, function (er, linkpath) {
  29. if (er) return self.error(er)
  30. self.linkpath = self.props.linkpath = linkpath
  31. self.emit('linkpath', linkpath)
  32. Reader.prototype._stat.call(self, currentStat)
  33. })
  34. }
  35. LinkReader.prototype._read = function () {
  36. var self = this
  37. if (self._paused) return
  38. // basically just a no-op, since we got all the info we need
  39. // from the _stat method
  40. if (!self._ended) {
  41. self.emit('end')
  42. self.emit('close')
  43. self._ended = true
  44. }
  45. }