space = (mork_num) (end - at);
space = end - at;
morkStream::Write(morkEnv* ev, const void* inBuf, mork_size inSize){  mork_num outActual = 0;  morkFile* file = mStream_ContentFile;  if ( this->IsOpenActiveAndMutableFile() && file )  {    mork_u1* end = mStream_WriteEnd; // byte after last buffered byte    if ( end ) // file is open for write access?    {      if ( inSize ) // caller provided any input?      {        const mork_u1* source = (const mork_u1*) inBuf; // from where        if ( source ) // caller passed good buffer address?        {          mork_u1* at = mStream_At;          mork_u1* buf = mStream_Buf;          if ( at >= buf && at <= end ) // expected cursor order?          {            mork_num space = (mork_num) (end - at); // space left in buffer                        mork_num quantum = inSize; // number of bytes to write            if ( quantum > space ) // more than buffer size?              quantum = space; // restrict to avail space                          if ( quantum ) // any space left in the buffer?            {              mStream_Dirty = morkBool_kTrue; // to ensure later flush              MORK_MEMCPY(at, source, quantum); // into buffer                            mStream_At += quantum; // advance past written bytes              outActual += quantum;  // this much written so far              source += quantum; // in case we need to write more              inSize -= quantum; // filled this much of request            }                        if ( inSize ) // we still need to write more content?            {              // We need to write more bytes directly to the              // content file, without local buffering.  We have              // exhausted the local buffer, so we need to flush              // it and empty it, and adjust the current buf pos.              // After flushing, if the rest of the write fits              // inside the buffer, we will put bytes into the              // buffer rather than write them to content file.                            if ( mStream_Dirty )                this->Flush(ev); // will update mStream_BufPos              at = mStream_At;              if ( at < buf || at > end ) // bad cursor?                this->NewBadCursorOrderError(ev);                              if ( ev->Good() ) // no errors?              {                space = (mork_num) (end - at); // space left in buffer                if ( space > inSize ) // write to buffer?                {                  mStream_Dirty = morkBool_kTrue; // ensure flush                  MORK_MEMCPY(at, source, inSize); // copy                                    mStream_At += inSize; // past written bytes                  outActual += inSize;  // this much written                }                else // directly to content file instead                {                  file->Seek(ev, mStream_BufPos); // set pos                                      if ( ev->Good() ) // no seek error?                  {                    mork_num actual =                      file->Write(ev, source, inSize);                    if ( ev->Good() ) // no write error?                    {                      outActual += actual;                      mStream_BufPos += actual;                    }                  }                }              }            }          }          else this->NewBadCursorOrderError(ev);        }        else this->NewNullStreamBufferError(ev);      }    }    else this->NewCantWriteSourceError(ev);  }  else this->NewFileDownError(ev);    if ( ev->Bad() )    outActual = 0;  return outActual;}