ZipMemFile.h

Go to the documentation of this file.
00001 
00002 // $RCSfile: ZipMemFile.h,v $
00003 // $Revision: 1.5 $
00004 // $Date: 2006/01/28 20:18:12 $ $Author: Tadeusz Dracz $
00006 // This source file is part of the ZipArchive library source distribution and
00007 // is Copyrighted 2000 - 2006 by Tadeusz Dracz (http://www.artpol-software.com/)
00008 //
00009 // This program is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 // 
00014 // For the licensing details see the file License.txt
00016 
00022 #if !defined(AFX_ZIPMEMFILE_H__EA73AB25_6B51_4C5E_8D78_BAC95812598F__INCLUDED_)
00023 #define AFX_ZIPMEMFILE_H__EA73AB25_6B51_4C5E_8D78_BAC95812598F__INCLUDED_
00024 
00025 #if _MSC_VER > 1000
00026 #pragma once
00027 #endif // _MSC_VER > 1000
00028 #include "ZipAbstractFile.h"
00029 #include "ZipString.h"
00030 #include "ZipExport.h"
00031 
00036 class ZIP_API CZipMemFile : public CZipAbstractFile
00037 {
00038 protected:
00039  size_t m_nGrowBy, m_nPos;
00040  size_t m_nBufSize, m_nDataSize;
00041  BYTE* m_lpBuf;
00042  bool m_bAutoDelete;
00043  void Free()
00044  {
00045   if (m_lpBuf)
00046   {
00047    free(m_lpBuf);
00048    m_lpBuf = NULL;
00049   }
00050  }
00051  void Init()
00052  {
00053   m_nGrowBy = m_nPos = 0;
00054   m_nBufSize = m_nDataSize = 0;
00055   m_lpBuf = NULL;
00056 
00057  }
00058  void Grow(size_t nBytes);
00059 public:
00060  bool IsClosed() const { return m_lpBuf == NULL;}
00061  void Flush(){}
00062 
00063  ZIP_ULONGLONG Seek(ZIP_LONGLONG lOff, int nFrom);
00064  ZIP_ULONGLONG GetLength() const {return m_nDataSize;}
00065  void Write(const void* lpBuf, UINT nCount);
00066  UINT Read(void* lpBuf, UINT nCount);
00067  void SetLength(ZIP_ULONGLONG nNewLen);
00068  CZipString GetFilePath() const  {return _T("");}  
00069  CZipMemFile(long nGrowBy = 1024)
00070  {
00071   Init();
00072   m_nGrowBy = nGrowBy;
00073   m_bAutoDelete = true;
00074  }
00075 
00076  
00077 
00078  CZipMemFile(BYTE* lpBuf, UINT nBufSize, long nGrowBy = 0)
00079  {
00080   Init();
00081   Attach(lpBuf, nBufSize, nGrowBy);
00082  }
00083 
00084  CZipMemFile(CZipMemFile& from)
00085  {
00086   Copy(from);
00087  }
00088 
00089  void Copy(CZipMemFile& from)
00090  {
00091   SetLength(from.m_nDataSize);
00092   from.Read(m_lpBuf, (UINT)from.m_nDataSize);
00093  }
00094 
00095  ZIP_ULONGLONG GetPosition() const { return m_nPos;}
00096  void Attach(BYTE* lpBuf, UINT nBufSize, long nGrowBy = 0)
00097  {
00098   Close();
00099   m_lpBuf = lpBuf;
00100   m_nGrowBy = nGrowBy;
00101   m_nBufSize = nBufSize;
00102   m_nDataSize = nGrowBy == 0 ? nBufSize : 0;
00103   m_bAutoDelete = false;
00104  }
00105  BYTE* Detach()
00106  {
00107   BYTE* b = m_lpBuf;
00108   Init();
00109   return b;
00110  }
00111  void Close()
00112  {
00113   if (m_bAutoDelete)
00114    Free();
00115   Init();
00116  }
00117  virtual ~CZipMemFile(){Close();}
00118 
00119 };
00120 
00121 #endif // !defined(AFX_ZIPMEMFILE_H__EA73AB25_6B51_4C5E_8D78_BAC95812598F__INCLUDED_)

ZipArchive Copyright © 2000 - 2006 Tadeusz Dracz . Generated at Fri Apr 7 13:55:23 2006.