lib/storage.js
/**
 * A torrent piece
 *
 * @param {number} index  piece index
 * @param {string} hash   sha1 hash (hex) for this piece
 * @param {Buffer|number} buffer backing buffer, or piece length if backing buffer is lazy
 * @param {boolean=} noVerify skip piece verification (used when seeding a new file)
 */
A torrent piece
@param {number} index  piece index
@param {string} hash   sha1 hash (hex) for this piece
@param {Buffer|number} buffer backing buffer, or piece length if backing buffer is lazy
@param {boolean=} noVerify skip piece verification (used when seeding a new file)
A torrent piece @param { number } index piece index @param { string } hash sha1 hash ( hex ) for this piece @param { Buffer|number } buffer backing buffer or piece length if backing buffer is lazy @param { boolean = } noVerify skip piece verification ( used when seeding a new file )
function Piece (index, hash, buffer, noVerify) {
  var self = this
  EventEmitter.call(self)
  if (!debug.enabled) self.setMaxListeners(0)
  self.index = index
  self.hash = hash
  self.noVerify = !!noVerify
  if (typeof buffer === 'number') {
    self.buffer = null
    self.length = buffer
  } else {
    self.buffer = buffer
    self.length = buffer.length
  }
  self._reset()
}
function Piece ( index , hash , buffer , noVerify ) { var self = this EventEmitter . call ( self ) if ( ! debug . enabled ) self . setMaxListeners ( 0 ) self . index = index self . hash = hash self . noVerify = ! ! noVerify if ( typeof buffer === 'number' ) { self . buffer = null self . length = buffer } else { self . buffer = buffer self . length = buffer . length } self . _reset ( ) }
A torrent piece
 @param {number} index  piece index
 @param {string} hash   sha1 hash (hex) for this piece
 @param {Buffer|number} buffer backing buffer, or piece length if backing buffer is lazy
 @param {boolean=} noVerify skip piece verification (used when seeding a new file)
A torrent piece @param { number } index piece index @param { string } hash sha1 hash ( hex ) for this piece @param { Buffer|number } buffer backing buffer or piece length if backing buffer is lazy @param { boolean = } noVerify skip piece verification ( used when seeding a new file )
// alloc buffer lazily // use buffer provided