haiku/headers/private/package/hpkg/DataWriters.h
Ingo Weinhold 1f633814fa hpkg format: compress the whole heap
Instead of handling compression for individual file/attribute data we
do now compress the whole heap where they are stored. This
significantly improves compression ratios. We still divide the
uncompressed data into 64 KiB chunks and use a chunk offset array for
the compressed chunks to allow for quick random access without too much
overhead. The tradeoff is a limited possible compression ratio -- i.e.
we won't be as good as tar.gz (though surprisingly with my test
archives we did better than zip).

The other package file sections (package attributes and TOC) are no
longer compressed individually. Their uncompressed data are simply
pushed onto the heap where the usual compression strategy applies. To
simplify things the repository format has been changed in the same
manner although it doesn't otherwise use the heap, since it only stores
meta data.

Due to the data compression having been exposed in public and private
API, this change touches a lot of package kit using code, including
packagefs and the boot loader packagefs support. The latter two haven't
been tested yet. Moreover packagefs needs a new kind of cache so we
avoid re-reading the same heap chunk for two different data items it
contains.
2013-05-25 01:12:25 +02:00

102 lines
1.9 KiB
C++

/*
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
#define _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/ZlibCompressor.h>
namespace BPackageKit {
namespace BHPKG {
class BErrorOutput;
namespace BPrivate {
class AbstractDataWriter {
public:
AbstractDataWriter();
virtual ~AbstractDataWriter();
uint64 BytesWritten() const
{ return fBytesWritten; }
virtual status_t WriteDataNoThrow(const void* buffer,
size_t size) = 0;
void WriteDataThrows(const void* buffer,
size_t size);
protected:
uint64 fBytesWritten;
};
class FDDataWriter : public AbstractDataWriter {
public:
FDDataWriter(int fd, off_t offset,
BErrorOutput* errorOutput);
virtual status_t WriteDataNoThrow(const void* buffer,
size_t size);
off_t Offset() const
{ return fOffset; }
private:
int fFD;
off_t fOffset;
BErrorOutput* fErrorOutput;
};
class ZlibDataWriter : public AbstractDataWriter, private BDataOutput {
public:
ZlibDataWriter(AbstractDataWriter* dataWriter);
void Init();
void Finish();
virtual status_t WriteDataNoThrow(const void* buffer,
size_t size);
private:
// BDataOutput
virtual status_t WriteData(const void* buffer, size_t size);
private:
AbstractDataWriter* fDataWriter;
ZlibCompressor fCompressor;
};
// inline implementations
inline void
AbstractDataWriter::WriteDataThrows(const void* buffer, size_t size)
{
status_t error = WriteDataNoThrow(buffer, size);
if (error != B_OK)
throw status_t(error);
}
} // namespace BPrivate
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_