-#if 0
- if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
- (size_t) OUTPUT_BUF_SIZE)
+ if( dest->bytes_written == dest->frag_length )
+ {
+ // Start the I/O suspension simply by returning false here:
+ return FALSE;
+ }
+
+ size_t output_buf_size = OUTPUT_BUF_SIZE;
+ if( (dest->bytes_written + OUTPUT_BUF_SIZE) > dest->frag_length )
+ {
+ output_buf_size = dest->frag_length - dest->bytes_written;
+ }
+ dest->outfile->write((char*)dest->buffer, output_buf_size);
+ size_t nbytes = output_buf_size; //dest->outfile->gcount();
+
+ if( nbytes <= 0 )