examples/terraformer-arcgis-fileparser.js
function tryRead(fd, buff, offset, length) {
  return new Promise((resolve, reject) => {
    fs.read(fd, buff, offset, length, null, (err, bytesRead, buffer) => {
      if (err) return reject(err);
      const buffLen = buffer.length;
      offset += bytesRead;
      if (offset >= buffLen) return resolve(buff);
      if ((offset + length) >= buffLen) length = buffLen - offset;
      return resolve();
    });
  })
  .then(
    (fullBuffer) => {
      return fullBuffer ? { data: fullBuffer, fd: fd }
                        : tryRead(fd, buff, offset, length);
    },
    (err) => { throw err; }
  );
}
function tryRead(fd, buff, offset, length) {
  return new Promise((resolve, reject) => {
    fs.read(fd, buff, offset, length, null, (err, bytesRead, buffer) => {
      if (err) return reject(err);
      const buffLen = buffer.length;
      offset += bytesRead;
      if (offset >= buffLen) return resolve(buff);
      if ((offset + length) >= buffLen) length = buffLen - offset;
      return resolve();
    });
  })
  .then(
    (fullBuffer) => {
      return fullBuffer ? { data: fullBuffer, fd: fd }
                        : tryRead(fd, buff, offset, length);
    },
    (err) => { throw err; }
  );
}
function tryRead ( fd , buff , offset , length ) { return new Promise ( ( resolve , reject ) => { fs . read ( fd , buff , offset , length , null , ( err , bytesRead , buffer ) => { if ( err ) return reject ( err ) ; const buffLen = buffer . length ; offset += bytesRead ; if ( offset >= buffLen ) return resolve ( buff ) ; if ( ( offset + length ) >= buffLen ) length = buffLen - offset ; return resolve ( ) ; } ) ; } ) . then ( ( fullBuffer ) => { return fullBuffer ? { data : fullBuffer , fd : fd } : tryRead ( fd , buff , offset , length ) ; } , ( err ) => { throw err ; } ) ; }
Reads file by chunkSize at a time. Will resolve with the buffer if it's full, otherwise will resolve with nothing, indicating another read should happen.
Reads file by chunkSize at a time . Will resolve with the buffer if it s full otherwise will resolve with nothing indicating another read should happen .