bin/view.js
function getMediaByBuffer (uri, cert, mode, user, safe, bufferURI) {
  var bufferPath = root
  if (bufferURI) {
    bufferPath += '/../' + url.parse(bufferURI).path
  }

  return new Promise(function (resolve, reject) {
    // var bufferPath = __dirname + '/../data/buffer/image/'
    debug('bufferPath', bufferPath)
    var files = fs.readdirSync(bufferPath)
    files.sort(function (a, b) {
      return fs.statSync(bufferPath + b).mtime.getTime() -
      fs.statSync(bufferPath + a).mtime.getTime()
    })

    var file = getNextFile(files)
    debug('nextFile', file)
    if (file) {
      var nextFile = bufferPath + file
      var ret = { 'uri': nextFile, 'cacheURI': urlencode.decode(file) }
      // var lastFile = bufferPath + files[files.length - 1]
      resolve(ret)
    } else {
      reject(new Error('nothing in buffer'))
    }

    balance(user).then((ret) => {
      return ret
    }).then(function (ret) {
      if (ret >= algos.getRandomUnseenImage.cost) {
        addMediaToBuffer(uri, cert, mode, user, safe, bufferURI)
      } else {
        reject(new Error('not enough funds'))
      }
    })
  })
}
function getMediaByBuffer (uri, cert, mode, user, safe, bufferURI) {
  var bufferPath = root
  if (bufferURI) {
    bufferPath += '/../' + url.parse(bufferURI).path
  }

  return new Promise(function (resolve, reject) {
    // var bufferPath = __dirname + '/../data/buffer/image/'
    debug('bufferPath', bufferPath)
    var files = fs.readdirSync(bufferPath)
    files.sort(function (a, b) {
      return fs.statSync(bufferPath + b).mtime.getTime() -
      fs.statSync(bufferPath + a).mtime.getTime()
    })

    var file = getNextFile(files)
    debug('nextFile', file)
    if (file) {
      var nextFile = bufferPath + file
      var ret = { 'uri': nextFile, 'cacheURI': urlencode.decode(file) }
      // var lastFile = bufferPath + files[files.length - 1]
      resolve(ret)
    } else {
      reject(new Error('nothing in buffer'))
    }

    balance(user).then((ret) => {
      return ret
    }).then(function (ret) {
      if (ret >= algos.getRandomUnseenImage.cost) {
        addMediaToBuffer(uri, cert, mode, user, safe, bufferURI)
      } else {
        reject(new Error('not enough funds'))
      }
    })
  })
}
function getMediaByBuffer ( uri , cert , mode , user , safe , bufferURI ) { var bufferPath = root if ( bufferURI ) { bufferPath += '/../' + url . parse ( bufferURI ) . path } return new Promise ( function ( resolve , reject ) { // var bufferPath = __dirname + '/../data/buffer/image/' debug ( 'bufferPath' , bufferPath ) var files = fs . readdirSync ( bufferPath ) files . sort ( function ( a , b ) { return fs . statSync ( bufferPath + b ) . mtime . getTime ( ) - fs . statSync ( bufferPath + a ) . mtime . getTime ( ) } ) var file = getNextFile ( files ) debug ( 'nextFile' , file ) if ( file ) { var nextFile = bufferPath + file var ret = { 'uri' : nextFile , 'cacheURI' : urlencode . decode ( file ) } // var lastFile = bufferPath + files[files.length - 1] resolve ( ret ) } else { reject ( new Error ( 'nothing in buffer' ) ) } balance ( user ) . then ( ( ret ) => { return ret } ) . then ( function ( ret ) { if ( ret >= algos . getRandomUnseenImage . cost ) { addMediaToBuffer ( uri , cert , mode , user , safe , bufferURI ) } else { reject ( new Error ( 'not enough funds' ) ) } } ) } ) }
Get Media item from buffer
@param  {string} uri       The uri to get it from.
@param  {string} cert      Location of an X.509 cert.
@param  {string} mode      Mode api | http | buffer.
@param  {string} user      The WebID of the user.
@param  {number} safe      Whether safe search is on.
@param  {string} bufferURI The URI of the buffer.
@return {object}           Promise with the row.
Get Media item from buffer