lib/decode.js
function decode (data, start, end, encoding) {
  if (data == null || data.length === 0) {
    return null
  }

  if (typeof start !== 'number' && encoding == null) {
    encoding = start
    start = undefined
  }

  if (typeof end !== 'number' && encoding == null) {
    encoding = end
    end = undefined
  }

  decode.position = 0
  decode.encoding = encoding || null

  decode.data = !(Buffer.isBuffer(data))
    ? Buffer.from(data)
    : data.slice(start, end)

  decode.bytes = decode.data.length

  return decode.next()
}
function decode (data, start, end, encoding) {
  if (data == null || data.length === 0) {
    return null
  }

  if (typeof start !== 'number' && encoding == null) {
    encoding = start
    start = undefined
  }

  if (typeof end !== 'number' && encoding == null) {
    encoding = end
    end = undefined
  }

  decode.position = 0
  decode.encoding = encoding || null

  decode.data = !(Buffer.isBuffer(data))
    ? Buffer.from(data)
    : data.slice(start, end)

  decode.bytes = decode.data.length

  return decode.next()
}
function decode ( data , start , end , encoding ) { if ( data == null || data . length === 0 ) { return null } if ( typeof start !== 'number' && encoding == null ) { encoding = start start = undefined } if ( typeof end !== 'number' && encoding == null ) { encoding = end end = undefined } decode . position = 0 decode . encoding = encoding || null decode . data = ! ( Buffer . isBuffer ( data ) ) ? Buffer . from ( data ) : data . slice ( start , end ) decode . bytes = decode . data . length return decode . next ( ) }
Decodes bencoded data.

@param  {Buffer} data
@param  {Number} start (optional)
@param  {Number} end (optional)
@param  {String} encoding (optional)
@return {Object|Array|Buffer|String|Number}
Decodes bencoded data .