B2G/gecko/toolkit/components/osfile/osfile_async_front.jsm
/**
   * Read bytes from this file to a new buffer.
   *
   * @param {number=} bytes If unspecified, read all the remaining bytes from
   * this file. If specified, read |bytes| bytes, or less if the file does not
   * contain that many bytes.
   * @return {promise}
   * @resolves {Uint8Array} An array containing the bytes read.
   */
Read bytes from this file to a new buffer.
@param {number=} bytes If unspecified, read all the remaining bytes from
this file. If specified, read |bytes| bytes, or less if the file does not
contain that many bytes.
@return {promise}
@resolves {Uint8Array} An array containing the bytes read.
Read bytes from this file to a new buffer . @param { number = } bytes If unspecified read all the remaining bytes from this file . If specified read |bytes| bytes or less if the file does not contain that many bytes . @return { promise } @resolves { Uint8Array } An array containing the bytes read .
function read(nbytes) {
    let self = this;
    let promise;
    if (nbytes != null) {
      promise = Promise.resolve(nbytes);
    } else {
      promise = this.stat();
      promise = promise.then(function withStat(stat) {
        return stat.size;
      });
    }
    let array;
    let size;
    promise = promise.then(
      function withSize(aSize) {
        size = aSize;
        array = new Uint8Array(size);
        return self.readTo(array);
      }
    );
    promise = promise.then(
      function afterReadTo(bytes) {
        if (bytes == size) {
          return array;
        } else {
          return array.subarray(0, bytes);
        }
      }
    );
    return promise;
  }
function read ( nbytes ) { let self = this ; let promise ; if ( nbytes != null ) { promise = Promise . resolve ( nbytes ) ; } else { promise = this . stat ( ) ; promise = promise . then ( function withStat ( stat ) { return stat . size ; } ) ; } let array ; let size ; promise = promise . then ( function withSize ( aSize ) { size = aSize ; array = new Uint8Array ( size ) ; return self . readTo ( array ) ; } ) ; promise = promise . then ( function afterReadTo ( bytes ) { if ( bytes == size ) { return array ; } else { return array . subarray ( 0 , bytes ) ; } } ) ; return promise ; }
Read bytes from this file to a new buffer.
Read bytes from this file to a new buffer .
// FIXME: Once bug 720949 has landed, we might be able to simplify // the implementation of |readAll|