btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / package / hpkg / PackageFileHeapWriter.h
blob49588f1686e0dc244a4d739ff436363f4193b277
1 /*
2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_WRITER_H_
6 #define _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_WRITER_H_
9 #include <Array.h>
10 #include <package/hpkg/PackageFileHeapAccessorBase.h>
13 class BCompressionParameters;
15 namespace BPrivate {
16 template<typename Value> class RangeArray;
20 namespace BPackageKit {
22 namespace BHPKG {
25 class BDataReader;
26 class BErrorOutput;
29 namespace BPrivate {
32 class PackageFileHeapReader;
35 class PackageFileHeapWriter : public PackageFileHeapAccessorBase {
36 public:
37 PackageFileHeapWriter(BErrorOutput* errorOutput,
38 BPositionIO* file, off_t heapOffset,
39 CompressionAlgorithmOwner*
40 compressionAlgorithm,
41 DecompressionAlgorithmOwner*
42 decompressionAlgorithm);
43 ~PackageFileHeapWriter();
45 void Init();
46 void Reinit(PackageFileHeapReader* heapReader);
48 status_t AddData(BDataReader& dataReader, off_t size,
49 uint64& _offset);
50 void AddDataThrows(const void* buffer, size_t size);
51 void RemoveDataRanges(
52 const ::BPrivate::RangeArray<uint64>&
53 ranges);
54 // doesn't truncate the file
55 status_t Finish();
57 protected:
58 virtual status_t ReadAndDecompressChunk(size_t chunkIndex,
59 void* compressedDataBuffer,
60 void* uncompressedDataBuffer);
62 private:
63 struct Chunk;
64 struct ChunkSegment;
65 struct ChunkBuffer;
67 friend struct ChunkBuffer;
69 private:
70 void _Uninit();
72 status_t _FlushPendingData();
73 status_t _WriteChunk(const void* data, size_t size,
74 bool mayCompress);
75 status_t _WriteDataCompressed(const void* data,
76 size_t size);
77 status_t _WriteDataUncompressed(const void* data,
78 size_t size);
80 void _PushChunks(ChunkBuffer& chunkBuffer,
81 uint64 startOffset, uint64 endOffset);
82 void _UnwriteLastPartialChunk();
84 private:
85 void* fPendingDataBuffer;
86 void* fCompressedDataBuffer;
87 size_t fPendingDataSize;
88 Array<uint64> fOffsets;
89 CompressionAlgorithmOwner* fCompressionAlgorithm;
93 } // namespace BPrivate
95 } // namespace BHPKG
97 } // namespace BPackageKit
100 #endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_WRITER_H_