Switch package kit to BZlibCompressionAlgorithm
... and remove the Zlib{Compressor,Decompressor} API.
This commit is contained in:
@@ -1 +0,0 @@
|
||||
#include <../private/support/ZlibCompressionBase.h>
|
||||
@@ -1 +0,0 @@
|
||||
#include <../private/support/ZlibCompressor.h>
|
||||
@@ -1 +0,0 @@
|
||||
#include <../private/support/ZlibDecompressor.h>
|
||||
@@ -6,8 +6,11 @@
|
||||
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_ACCESSOR_BASE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <new>
|
||||
|
||||
#include <Referenceable.h>
|
||||
|
||||
#include <CompressionAlgorithm.h>
|
||||
#include <package/hpkg/DataReader.h>
|
||||
|
||||
|
||||
@@ -22,6 +25,46 @@ class BErrorOutput;
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
template<typename Parameters>
|
||||
struct GenericCompressionAlgorithmOwner : BReferenceable {
|
||||
BCompressionAlgorithm* algorithm;
|
||||
Parameters* parameters;
|
||||
|
||||
GenericCompressionAlgorithmOwner(BCompressionAlgorithm* algorithm,
|
||||
Parameters* parameters)
|
||||
:
|
||||
algorithm(algorithm),
|
||||
parameters(parameters)
|
||||
{
|
||||
}
|
||||
|
||||
~GenericCompressionAlgorithmOwner()
|
||||
{
|
||||
delete algorithm;
|
||||
delete parameters;
|
||||
}
|
||||
|
||||
static GenericCompressionAlgorithmOwner* Create(
|
||||
BCompressionAlgorithm* algorithm, Parameters* parameters)
|
||||
{
|
||||
GenericCompressionAlgorithmOwner* owner
|
||||
= new(std::nothrow) GenericCompressionAlgorithmOwner(algorithm,
|
||||
parameters);
|
||||
if (owner == NULL) {
|
||||
delete algorithm;
|
||||
delete parameters;
|
||||
}
|
||||
|
||||
return owner;
|
||||
}
|
||||
};
|
||||
|
||||
typedef GenericCompressionAlgorithmOwner<BCompressionParameters>
|
||||
CompressionAlgorithmOwner;
|
||||
typedef GenericCompressionAlgorithmOwner<BDecompressionParameters>
|
||||
DecompressionAlgorithmOwner;
|
||||
|
||||
|
||||
class PackageFileHeapAccessorBase : public BAbstractBufferedDataReader {
|
||||
public:
|
||||
class OffsetArray;
|
||||
@@ -29,7 +72,9 @@ public:
|
||||
public:
|
||||
PackageFileHeapAccessorBase(
|
||||
BErrorOutput* errorOutput, int fd,
|
||||
off_t heapOffset);
|
||||
off_t heapOffset,
|
||||
DecompressionAlgorithmOwner*
|
||||
decompressionAlgorithm);
|
||||
virtual ~PackageFileHeapAccessorBase();
|
||||
|
||||
off_t HeapOffset() const
|
||||
@@ -77,6 +122,7 @@ protected:
|
||||
off_t fHeapOffset;
|
||||
uint64 fCompressedHeapSize;
|
||||
uint64 fUncompressedHeapSize;
|
||||
DecompressionAlgorithmOwner* fDecompressionAlgorithm;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ public:
|
||||
PackageFileHeapReader(BErrorOutput* errorOutput,
|
||||
int fd, off_t heapOffset,
|
||||
off_t compressedHeapSize,
|
||||
uint64 uncompressedHeapSize);
|
||||
uint64 uncompressedHeapSize,
|
||||
DecompressionAlgorithmOwner*
|
||||
decompressionAlgorithm);
|
||||
~PackageFileHeapReader();
|
||||
|
||||
status_t Init();
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <package/hpkg/PackageFileHeapAccessorBase.h>
|
||||
|
||||
|
||||
class BCompressionParameters;
|
||||
|
||||
namespace BPrivate {
|
||||
template<typename Value> class RangeArray;
|
||||
}
|
||||
@@ -34,7 +36,10 @@ class PackageFileHeapWriter : public PackageFileHeapAccessorBase {
|
||||
public:
|
||||
PackageFileHeapWriter(BErrorOutput* errorOutput,
|
||||
int fd, off_t heapOffset,
|
||||
int32 compressionLevel);
|
||||
CompressionAlgorithmOwner*
|
||||
compressionAlgorithm,
|
||||
DecompressionAlgorithmOwner*
|
||||
decompressionAlgorithm);
|
||||
~PackageFileHeapWriter();
|
||||
|
||||
void Init();
|
||||
@@ -81,7 +86,7 @@ private:
|
||||
void* fCompressedDataBuffer;
|
||||
size_t fPendingDataSize;
|
||||
Array<uint64> fOffsets;
|
||||
int32 fCompressionLevel;
|
||||
CompressionAlgorithmOwner* fCompressionAlgorithm;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||
|
||||
|
||||
class BCompressionAlgorithm;
|
||||
class BDecompressionParameters;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
@@ -10,12 +10,18 @@
|
||||
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/PackageFileHeapWriter.h>
|
||||
#include <package/hpkg/PackageWriter.h>
|
||||
#include <package/hpkg/Strings.h>
|
||||
|
||||
#include <package/PackageInfo.h>
|
||||
|
||||
#include <package/hpkg/PackageFileHeapWriter.h>
|
||||
|
||||
|
||||
class BCompressionAlgorithm;
|
||||
class BCompressionParameters;
|
||||
class BDecompressionParameters;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
@@ -156,6 +162,10 @@ protected:
|
||||
|
||||
protected:
|
||||
PackageFileHeapWriter* fHeapWriter;
|
||||
BCompressionAlgorithm* fCompressionAlgorithm;
|
||||
BCompressionParameters* fCompressionParameters;
|
||||
BCompressionAlgorithm* fDecompressionAlgorithm;
|
||||
BDecompressionParameters* fDecompressionParameters;
|
||||
|
||||
private:
|
||||
static const BHPKGAttributeID kDefaultVersionAttributeID
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ZLIB_COMPRESSION_BASE_H_
|
||||
#define _ZLIB_COMPRESSION_BASE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class BDataIO;
|
||||
|
||||
|
||||
class BZlibCompressionBase {
|
||||
public:
|
||||
BZlibCompressionBase(BDataIO* output);
|
||||
~BZlibCompressionBase();
|
||||
|
||||
static status_t TranslateZlibError(int error);
|
||||
|
||||
protected:
|
||||
struct ZStream;
|
||||
|
||||
protected:
|
||||
status_t CreateStream();
|
||||
void DeleteStream();
|
||||
|
||||
protected:
|
||||
BDataIO* fOutput;
|
||||
ZStream* fStream;
|
||||
};
|
||||
|
||||
|
||||
#endif // _ZLIB_COMPRESSION_BASE_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ZLIB_COMPRESSOR_H_
|
||||
#define _ZLIB_COMPRESSOR_H_
|
||||
|
||||
|
||||
#include <ZlibCompressionBase.h>
|
||||
|
||||
|
||||
class BDataIO;
|
||||
|
||||
|
||||
// compression level
|
||||
enum {
|
||||
B_ZLIB_COMPRESSION_NONE = 0,
|
||||
B_ZLIB_COMPRESSION_FASTEST = 1,
|
||||
B_ZLIB_COMPRESSION_BEST = 9,
|
||||
B_ZLIB_COMPRESSION_DEFAULT = -1,
|
||||
};
|
||||
|
||||
|
||||
class BZlibCompressor : public BZlibCompressionBase {
|
||||
public:
|
||||
BZlibCompressor(BDataIO* output);
|
||||
~BZlibCompressor();
|
||||
|
||||
status_t Init(int compressionLevel
|
||||
= B_ZLIB_COMPRESSION_BEST);
|
||||
status_t CompressNext(const void* input,
|
||||
size_t inputSize);
|
||||
status_t Finish();
|
||||
|
||||
static status_t CompressSingleBuffer(const void* input,
|
||||
size_t inputSize, void* output,
|
||||
size_t outputSize, size_t& _compressedSize,
|
||||
int compressionLevel
|
||||
= B_ZLIB_COMPRESSION_BEST);
|
||||
};
|
||||
|
||||
|
||||
#endif // _ZLIB_COMPRESSOR_H_
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ZLIB_DECOMPRESSOR_H_
|
||||
#define _ZLIB_DECOMPRESSOR_H_
|
||||
|
||||
|
||||
#include <ZlibCompressionBase.h>
|
||||
|
||||
|
||||
class BZlibDecompressor : public BZlibCompressionBase {
|
||||
public:
|
||||
BZlibDecompressor(BDataIO* output);
|
||||
~BZlibDecompressor();
|
||||
|
||||
status_t Init();
|
||||
status_t DecompressNext(const void* input,
|
||||
size_t inputSize);
|
||||
status_t Finish();
|
||||
|
||||
static status_t DecompressSingleBuffer(const void* input,
|
||||
size_t inputSize, void* output,
|
||||
size_t outputSize,
|
||||
size_t& _uncompressedSize);
|
||||
|
||||
private:
|
||||
bool fFinished;
|
||||
};
|
||||
|
||||
|
||||
#endif // _ZLIB_DECOMPRESSOR_H_
|
||||
Reference in New Issue
Block a user