Logo Search packages:      
Sourcecode: harbour version File versions  Download package

bool CZipArchive::WriteNewFile ( const void *  pBuf,
DWORD  iSize 
)

Compress the contents of the buffer and write it to a new file.

Parameters:
pBuf the buffer containing the data to be compressed and written
iSize the number of bytes to be written from the buffer
Returns:
false if the new file hasn't been opened yet
Note:
Throws exceptions.
See also:
OpenNewFile

Definition at line 831 of file ziparchive.cpp.

References CheckForError(), compress, CryptEncodeBuffer(), CurrentFile(), CZipAutoBuffer::GetSize(), m_iFileOpened, m_info, CZipArchive::CZipInternalInfo::m_pBuffer, m_storage, CZipArchive::CZipInternalInfo::m_stream, CZipArchive::CZipInternalInfo::m_uComprLeft, CZipFileHeader::m_uCrc32, CZipFileHeader::m_uMethod, and CZipStorage::Write().

Referenced by AddNewFile().

{
      if (m_iFileOpened != compress)
      {
            TRACE(_T("%s(%i) : A new file must be opened.\n"),__FILE__,__LINE__);
            return false;
      }


    m_info.m_stream.next_in = (Bytef*)pBuf;
    m_info.m_stream.avail_in = iSize;
    CurrentFile()->m_uCrc32 = crc32(CurrentFile()->m_uCrc32, (Bytef*)pBuf, iSize);


    while (m_info.m_stream.avail_in > 0)
    {
        if (m_info.m_stream.avail_out == 0)
        {
                  CryptEncodeBuffer();
                  m_storage.Write(m_info.m_pBuffer, m_info.m_uComprLeft, false);
                  m_info.m_uComprLeft = 0;
            m_info.m_stream.avail_out = m_info.m_pBuffer.GetSize();
            m_info.m_stream.next_out = (Bytef*)(char*)m_info.m_pBuffer;
        }

        if (CurrentFile()->m_uMethod == Z_DEFLATED)
        {
            DWORD uTotal = m_info.m_stream.total_out;
            int err = deflate(&m_info.m_stream,  Z_NO_FLUSH);
                  CheckForError(err);
            m_info.m_uComprLeft += m_info.m_stream.total_out - uTotal;
        }
        else
        {
            DWORD uToCopy = (m_info.m_stream.avail_in < m_info.m_stream.avail_out)
                        ? m_info.m_stream.avail_in : m_info.m_stream.avail_out;

                  memcpy(m_info.m_stream.next_out, m_info.m_stream.next_in, uToCopy);

            m_info.m_stream.avail_in -= uToCopy;
            m_info.m_stream.avail_out -= uToCopy;
            m_info.m_stream.next_in += uToCopy;
            m_info.m_stream.next_out += uToCopy;
            m_info.m_stream.total_in += uToCopy;
            m_info.m_stream.total_out += uToCopy;
            m_info.m_uComprLeft += uToCopy;
        }
    }

      return true;
}


Generated by  Doxygen 1.6.0   Back to index