lib/storage.js
/**
 * A torrent file
 *
 * @param {Storage} storage       Storage container object
 * @param {Object}  file          the file object from the parsed torrent
 * @param {Array.<Piece>} pieces  backing pieces for this file
 * @param {number}  pieceLength   the length in bytes of a non-terminal piece
 */
A torrent file
@param {Storage} storage       Storage container object
@param {Object}  file          the file object from the parsed torrent
@param {Array.} pieces  backing pieces for this file
@param {number}  pieceLength   the length in bytes of a non-terminal piece
A torrent file @param { Storage } storage Storage container object @param { Object } file the file object from the parsed torrent @param { Array . } pieces backing pieces for this file @param { number } pieceLength the length in bytes of a non - terminal piece
function File (storage, file, pieces, pieceLength) {
  var self = this
  EventEmitter.call(self)
  if (!debug.enabled) self.setMaxListeners(0)
  self.storage = storage
  self.name = file.name
  self.path = file.path
  self.length = file.length
  self.offset = file.offset
  self.pieces = pieces
  self.pieceLength = pieceLength
  self.done = false
  self.pieces.forEach(function (piece) {
    piece.on('done', function () {
      self._checkDone()
    })
  })
  self._checkDone()
}
function File ( storage , file , pieces , pieceLength ) { var self = this EventEmitter . call ( self ) if ( ! debug . enabled ) self . setMaxListeners ( 0 ) self . storage = storage self . name = file . name self . path = file . path self . length = file . length self . offset = file . offset self . pieces = pieces self . pieceLength = pieceLength self . done = false self . pieces . forEach ( function ( piece ) { piece . on ( 'done' , function ( ) { self . _checkDone ( ) } ) } ) self . _checkDone ( ) }
A torrent file
 @param {Storage} storage       Storage container object
 @param {Object}  file          the file object from the parsed torrent
 @param {Array.<Piece>} pieces  backing pieces for this file
 @param {number}  pieceLength   the length in bytes of a non-terminal piece
A torrent file @param { Storage } storage Storage container object @param { Object } file the file object from the parsed torrent @param { Array . <Piece > } pieces backing pieces for this file @param { number } pieceLength the length in bytes of a non - terminal piece
// if the file is zero-length, it will be done upon initialization