Hello Donald,
Perhaps you're not worried about performance, but wouldn't reading
4096 1 byte blocks be substantially slower than reading 1 4096 byte
block? You just need to do a bit of extra arithmetic to turn the
number of blocks read from FileRead into number of bytes read.
Adrien.
Tuesday, January 17, 2006, 9:23:50 PM, you wrote:
DCK> Problem solved!!!!!
DCK> I found out what was wrong. I just assumed (after quickly skimming over the
DCK> docs) that FileRead returned the number of bytes read. It in fact returns
DCK> the number of blocks read. I had the number of blocks to write set at 1 and
DCK> the size of each block set to 4096. FileRead was doing what it was supposed
DCK> to do, but not how I thought. This meant that readBytes was being returned
DCK> as 1 and not the 4096 that I thought!!! So, VFSWrite was only writing 1
DCK> byte!!! Explaining why it was taking centuries to write a little of
anything
DCK> (and why it was writing garbage). I fixed it by setting the block size in
DCK> FileRead to 1 and the number of blocks to 4096 (so it would read 4096
blocks
DCK> of 1 byte, or about 4k). This is what my code now looks like:
DCK> for (copied = 0; copied < size; copied += numBytesWrittenP) {
DCK> //if (FileEOF(cache))
DCK> // break;
DCK> //FileClearerr(cache);
DCK> readBytes = FileRead( cache, tempData, /*VFS_WRITE_BLOCK, 1*/1,
DCK> VFS_WRITE_BLOCK, &fileError);
DCK> if (fileError != errNone) {
DCK> cacheError(fileError);
DCK> loopError = true;
DCK> break;
DCK> }
DCK> do {
DCK> err = VFSFileWrite(fileRefP, readBytes - bufferoffset, tempData
+
DCK> bufferoffset,
DCK> &numBytesWrittenP);
DCK> if (err != errNone) {
DCK> VfsError(err);
DCK> loopError = true;
DCK> break;
DCK> }
DCK> bufferoffset += numBytesWrittenP;
DCK> } while (bufferoffset < readBytes);
DCK> bufferoffset = 0;
DCK> if (loopError == true)
DCK> break;
DCK> }
DCK> By the way, should I leave the "if (FileEOF(cache)) break;
DCK> FileClearerr(cache);" in there? FileRead seems to return errFileEOF (or
DCK> something like that) on its own, I just don't know if this is specific to
DCK> any OS release.
DCK> Now to add a progress dialog box.
DCK> Thanks for all of the help.
DCK> Regards,
DCK> Donald
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/