2013-05-18 06:11:01 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_WRITER_H_
|
|
|
|
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_WRITER_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <Array.h>
|
|
|
|
#include <package/hpkg/PackageFileHeapAccessorBase.h>
|
|
|
|
|
|
|
|
|
2014-06-30 23:35:03 +04:00
|
|
|
class BCompressionParameters;
|
|
|
|
|
2013-05-18 06:11:01 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
template<typename Value> class RangeArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
|
|
|
|
namespace BHPKG {
|
|
|
|
|
|
|
|
|
|
|
|
class BDataReader;
|
|
|
|
class BErrorOutput;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
|
|
|
class PackageFileHeapReader;
|
|
|
|
|
|
|
|
|
2014-06-24 00:55:16 +04:00
|
|
|
class PackageFileHeapWriter : public PackageFileHeapAccessorBase {
|
2013-05-18 06:11:01 +04:00
|
|
|
public:
|
|
|
|
PackageFileHeapWriter(BErrorOutput* errorOutput,
|
2014-07-12 15:34:56 +04:00
|
|
|
BPositionIO* file, off_t heapOffset,
|
2014-06-30 23:35:03 +04:00
|
|
|
CompressionAlgorithmOwner*
|
|
|
|
compressionAlgorithm,
|
|
|
|
DecompressionAlgorithmOwner*
|
|
|
|
decompressionAlgorithm);
|
2013-05-18 06:11:01 +04:00
|
|
|
~PackageFileHeapWriter();
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Reinit(PackageFileHeapReader* heapReader);
|
|
|
|
|
|
|
|
status_t AddData(BDataReader& dataReader, off_t size,
|
|
|
|
uint64& _offset);
|
2014-06-24 00:55:16 +04:00
|
|
|
void AddDataThrows(const void* buffer, size_t size);
|
2013-05-18 06:11:01 +04:00
|
|
|
void RemoveDataRanges(
|
|
|
|
const ::BPrivate::RangeArray<uint64>&
|
|
|
|
ranges);
|
|
|
|
// doesn't truncate the file
|
|
|
|
status_t Finish();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual status_t ReadAndDecompressChunk(size_t chunkIndex,
|
|
|
|
void* compressedDataBuffer,
|
|
|
|
void* uncompressedDataBuffer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Chunk;
|
|
|
|
struct ChunkSegment;
|
|
|
|
struct ChunkBuffer;
|
|
|
|
|
2013-05-19 06:32:39 +04:00
|
|
|
friend struct ChunkBuffer;
|
|
|
|
|
2013-05-18 06:11:01 +04:00
|
|
|
private:
|
|
|
|
void _Uninit();
|
|
|
|
|
|
|
|
status_t _FlushPendingData();
|
|
|
|
status_t _WriteChunk(const void* data, size_t size,
|
|
|
|
bool mayCompress);
|
|
|
|
status_t _WriteDataCompressed(const void* data,
|
|
|
|
size_t size);
|
|
|
|
status_t _WriteDataUncompressed(const void* data,
|
|
|
|
size_t size);
|
|
|
|
|
|
|
|
void _PushChunks(ChunkBuffer& chunkBuffer,
|
|
|
|
uint64 startOffset, uint64 endOffset);
|
2013-05-19 06:32:39 +04:00
|
|
|
void _UnwriteLastPartialChunk();
|
2013-05-18 06:11:01 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void* fPendingDataBuffer;
|
|
|
|
void* fCompressedDataBuffer;
|
|
|
|
size_t fPendingDataSize;
|
|
|
|
Array<uint64> fOffsets;
|
2014-06-30 23:35:03 +04:00
|
|
|
CompressionAlgorithmOwner* fCompressionAlgorithm;
|
2013-05-18 06:11:01 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
} // namespace BHPKG
|
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_WRITER_H_
|