Welcome to mirror list, hosted at ThFree Co, Russian Federation.

7zOut.h « 7z « Archive « 7zip - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cccc813a0912178315bc9200f1d82cd05a9d08d7 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// 7z/Out.h

#ifndef __7Z_OUT_H
#define __7Z_OUT_H

#include "7zHeader.h"
#include "7zItem.h"
#include "7zCompressionMode.h"
#include "7zEncode.h"

#include "../../Common/OutBuffer.h"
#include "../../../Common/DynamicBuffer.h"
#include "../../../Common/CRC.h"

namespace NArchive {
namespace N7z {

class CWriteBufferLoc
{
  Byte *_data;
  size_t _size;
  size_t _pos;
public:
  CWriteBufferLoc(): _size(0), _pos(0) {}
  void Init(Byte *data, size_t size)  
  { 
    _pos = 0;
    _data = data;
    _size = size; 
  }
  HRESULT Write(const void *data, size_t size)
  {
    if (_pos + size > _size)
      return E_FAIL;
    memmove(_data + _pos, data, size);
    _pos += size;
    return S_OK; 
  }
};

class CWriteDynamicBuffer
{
  CByteDynamicBuffer _buffer;
  size_t _pos;
public:
  CWriteDynamicBuffer(): _pos(0) {}
  void Init()  
  { 
    _pos = 0;
  }
  void Write(const void *data, size_t size)
  {
    if (_pos + size > _buffer.GetCapacity())
      _buffer.EnsureCapacity(_pos + size);
    memmove(((Byte *)_buffer) +_pos, data, size);
    _pos += size;
  }
  operator Byte *() { return (Byte *)_buffer; };
  operator const Byte *() const { return (const Byte *)_buffer; };
  size_t GetSize() const { return _pos; }
};

struct CHeaderOptions
{
  bool UseAdditionalHeaderStreams;
  bool CompressMainHeader;
  bool WriteModified;
  bool WriteCreated;
  bool WriteAccessed;

  CHeaderOptions(): 
      UseAdditionalHeaderStreams(false), 
      CompressMainHeader(true),
      WriteModified(true),
      WriteCreated(false),
      WriteAccessed(false) {} 
};

class COutArchive
{
  UInt64 _prefixHeaderPos;

  HRESULT WriteDirect(const void *data, UInt32 size);
  HRESULT WriteDirectByte(Byte b) { return WriteDirect(&b, 1); }
  HRESULT WriteDirectUInt32(UInt32 value);
  HRESULT WriteDirectUInt64(UInt64 value);
  
  HRESULT WriteBytes(const void *data, size_t size);
  HRESULT WriteBytes(const CByteBuffer &data);
  HRESULT WriteByte(Byte b);
  HRESULT WriteUInt32(UInt32 value);
  HRESULT WriteNumber(UInt64 value);
  HRESULT WriteID(UInt64 value) { return WriteNumber(value); }

  HRESULT WriteFolder(const CFolder &folder);
  HRESULT WriteFileHeader(const CFileItem &itemInfo);
  HRESULT WriteBoolVector(const CBoolVector &boolVector);
  HRESULT WriteHashDigests(
      const CRecordVector<bool> &digestsDefined,
      const CRecordVector<UInt32> &hashDigests);

  HRESULT WritePackInfo(
      UInt64 dataOffset,
      const CRecordVector<UInt64> &packSizes,
      const CRecordVector<bool> &packCRCsDefined,
      const CRecordVector<UInt32> &packCRCs);

  HRESULT WriteUnPackInfo(
      bool externalFolders,
      CNum externalFoldersStreamIndex,
      const CObjectVector<CFolder> &folders);

  HRESULT WriteSubStreamsInfo(
      const CObjectVector<CFolder> &folders,
      const CRecordVector<CNum> &numUnPackStreamsInFolders,
      const CRecordVector<UInt64> &unPackSizes,
      const CRecordVector<bool> &digestsDefined,
      const CRecordVector<UInt32> &hashDigests);

  /*
  HRESULT WriteStreamsInfo(
      UInt64 dataOffset,
      const CRecordVector<UInt64> &packSizes,
      const CRecordVector<bool> &packCRCsDefined,
      const CRecordVector<UInt32> &packCRCs,
      bool externalFolders,
      UInt64 externalFoldersStreamIndex,
      const CObjectVector<CFolder> &folders,
      const CRecordVector<CNum> &numUnPackStreamsInFolders,
      const CRecordVector<UInt64> &unPackSizes,
      const CRecordVector<bool> &digestsDefined,
      const CRecordVector<UInt32> &hashDigests);
  */


  HRESULT WriteTime(const CObjectVector<CFileItem> &files, Byte type,
      bool isExternal, CNum externalDataIndex);

  HRESULT EncodeStream(CEncoder &encoder, const Byte *data, size_t dataSize,
      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);
  HRESULT EncodeStream(CEncoder &encoder, const CByteBuffer &data, 
      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);
  HRESULT WriteHeader(const CArchiveDatabase &database,
      const CCompressionMethodMode *options, 
      const CHeaderOptions &headerOptions,
      UInt64 &headerOffset);
  
  bool _mainMode;

  bool _dynamicMode;

  bool _countMode;
  size_t _countSize;
  COutBuffer _outByte;
  CWriteBufferLoc _outByte2;
  CWriteDynamicBuffer _dynamicBuffer;
  CCRC _crc;

  #ifdef _7Z_VOL
  bool _endMarker;
  #endif

  HRESULT WriteSignature();
  #ifdef _7Z_VOL
  HRESULT WriteFinishSignature();
  #endif
  HRESULT WriteStartHeader(const CStartHeader &h);
  #ifdef _7Z_VOL
  HRESULT WriteFinishHeader(const CFinishHeader &h);
  #endif
  CMyComPtr<IOutStream> Stream;
public:

  COutArchive() { _outByte.Create(1 << 16); }
  CMyComPtr<ISequentialOutStream> SeqStream;
  HRESULT Create(ISequentialOutStream *stream, bool endMarker);
  void Close();
  HRESULT SkeepPrefixArchiveHeader();
  HRESULT WriteDatabase(const CArchiveDatabase &database,
      const CCompressionMethodMode *options, 
      const CHeaderOptions &headerOptions);

  #ifdef _7Z_VOL
  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);
  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);
  #endif

};

}}

#endif