"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/fstream/lib/link-reader.js" (7 Feb 2017, 1507 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 
    7 module.exports = LinkReader
    8 
    9 var fs = require('graceful-fs')
   10 var inherits = require('inherits')
   11 var Reader = require('./reader.js')
   12 
   13 inherits(LinkReader, Reader)
   14 
   15 function LinkReader (props) {
   16   var self = this
   17   if (!(self instanceof LinkReader)) {
   18     throw new Error('LinkReader must be called as constructor.')
   19   }
   20 
   21   if (!((props.type === 'Link' && props.Link) ||
   22     (props.type === 'SymbolicLink' && props.SymbolicLink))) {
   23     throw new Error('Non-link type ' + props.type)
   24   }
   25 
   26   Reader.call(self, props)
   27 }
   28 
   29 // When piping a LinkReader into a LinkWriter, we have to
   30 // already have the linkpath property set, so that has to
   31 // happen *before* the "ready" event, which means we need to
   32 // override the _stat method.
   33 LinkReader.prototype._stat = function (currentStat) {
   34   var self = this
   35   fs.readlink(self._path, function (er, linkpath) {
   36     if (er) return self.error(er)
   37     self.linkpath = self.props.linkpath = linkpath
   38     self.emit('linkpath', linkpath)
   39     Reader.prototype._stat.call(self, currentStat)
   40   })
   41 }
   42 
   43 LinkReader.prototype._read = function () {
   44   var self = this
   45   if (self._paused) return
   46   // basically just a no-op, since we got all the info we need
   47   // from the _stat method
   48   if (!self._ended) {
   49     self.emit('end')
   50     self.emit('close')
   51     self._ended = true
   52   }
   53 }