File: ZipMemFile.h

package info (click to toggle)
tuxcmd-modules 0.6.70%2Bds-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,872 kB
  • sloc: cpp: 11,743; ansic: 8,064; makefile: 245
file content (129 lines) | stat: -rw-r--r-- 2,830 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// For the licensing details refer to the License.txt file.
//
// Web Site: http://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////

/**
* \file ZipMemFile.h
* Includes the CZipMemFile class.
*
*/
#if !defined(ZIPARCHIVE_ZIPMEMFILE_DOT_H)
#define ZIPARCHIVE_ZIPMEMFILE_DOT_H

#if _MSC_VER > 1000
#pragma once
#endif

#include "ZipAbstractFile.h"
#include "ZipString.h"
#include "ZipExport.h"

/**
	Represents a file in memory.
	Automatically grows when necessary.
*/
class ZIP_API CZipMemFile : public CZipAbstractFile
{
protected:
	size_t m_nGrowBy, m_nPos;
	size_t m_nBufSize, m_nDataSize;
	BYTE* m_lpBuf;
	bool m_bAutoDelete;
	void Free()
	{
		if (m_lpBuf)
		{
			free(m_lpBuf);
			m_lpBuf = NULL;
		}
	}
	void Init()
	{
		m_nGrowBy = m_nPos = 0;
		m_nBufSize = m_nDataSize = 0;
		m_lpBuf = NULL;

	}
	void Grow(size_t nBytes);
public:
	bool IsClosed() const { return m_lpBuf == NULL;}
	void Flush(){}

	ZIP_FILE_USIZE Seek(ZIP_FILE_SIZE lOff, int nFrom);
	ZIP_FILE_USIZE GetLength() const {return m_nDataSize;}
	void Write(const void* lpBuf, UINT nCount);
	UINT Read(void* lpBuf, UINT nCount);
	void SetLength(ZIP_FILE_USIZE nNewLen);
	CZipString GetFilePath() const  {return _T("");} 	
	CZipMemFile(long nGrowBy = 1024)
	{
		Init();
		m_nGrowBy = nGrowBy;
		m_bAutoDelete = true;
	}

	

	CZipMemFile(BYTE* lpBuf, UINT nBufSize, long nGrowBy = 0)
	{
		Init();
		Attach(lpBuf, nBufSize, nGrowBy);
	}

	CZipMemFile(CZipMemFile& from)
	{
		Copy(from);
	}

	void Copy(CZipMemFile& from)
	{
		SetLength(from.m_nDataSize);
		from.Read(m_lpBuf, (UINT)from.m_nDataSize);
	}

	ZIP_FILE_USIZE GetPosition() const {	return m_nPos;}
	void Attach(BYTE* lpBuf, UINT nBufSize, long nGrowBy = 0)
	{
		Close();
		m_lpBuf = lpBuf;
		m_nGrowBy = nGrowBy;
		m_nBufSize = nBufSize;
		m_nDataSize = nGrowBy == 0 ? nBufSize : 0;
		m_bAutoDelete = false;
	}

	void ReInit(long nGrowBy = 1024)
	{
		Close();
		Init();
		m_nGrowBy = nGrowBy;
		m_bAutoDelete = true;
	}

	BYTE* Detach()
	{
		BYTE* b = m_lpBuf;
		Init();
		return b;
	}
	void Close()
	{
		if (m_bAutoDelete)
			Free();
		Init();
	}
	virtual ~CZipMemFile(){Close();}

};

#endif // !defined(ZIPARCHIVE_ZIPMEMFILE_DOT_H)