Problem solved!!!!!

I found out what was wrong. I just assumed (after quickly skimming over the
docs) that FileRead returned the number of bytes read. It in fact returns
the number of blocks read. I had the number of blocks to write set at 1 and
the size of each block set to 4096. FileRead was doing what it was supposed
to do, but not how I thought. This meant that readBytes was being returned
as 1 and not the 4096 that I thought!!! So, VFSWrite was only writing 1
byte!!! Explaining why it was taking centuries to write a little of anything
(and why it was writing garbage). I fixed it by setting the block size in
FileRead to 1 and the number of blocks to 4096 (so it would read 4096 blocks
of 1 byte, or about 4k). This is what my code now looks like:

 for (copied = 0; copied < size; copied += numBytesWrittenP) {

  //if (FileEOF(cache))
  // break;

  //FileClearerr(cache);

  readBytes = FileRead( cache, tempData, /*VFS_WRITE_BLOCK, 1*/1,
VFS_WRITE_BLOCK, &fileError);
  if (fileError != errNone) {
   cacheError(fileError);
   loopError = true;
   break;
  }

  do {
           err = VFSFileWrite(fileRefP, readBytes - bufferoffset, tempData +
bufferoffset,
         &numBytesWrittenP);
           if (err != errNone) {
    VfsError(err);
    loopError = true;
    break;
   }

           bufferoffset += numBytesWrittenP;
       } while (bufferoffset < readBytes);

  bufferoffset = 0;

  if (loopError == true)
   break;
 }

By the way, should I leave the "if (FileEOF(cache)) break;
FileClearerr(cache);" in there? FileRead seems to return errFileEOF (or
something like that) on its own, I just don't know if this is specific to
any OS release.

Now to add a progress dialog box.

Thanks for all of the help.

Regards,
Donald



-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to