Move package kit Zlib* classes to support kit
Also move to B* namespace and no longer expose the zlib dependency in the headers.
This commit is contained in:
parent
b773d89eba
commit
6a89a36aa0
@ -1 +0,0 @@
|
||||
#include <../private/package/hpkg/ZlibCompressionBase.h>
|
@ -1 +0,0 @@
|
||||
#include <../private/package/hpkg/ZlibCompressor.h>
|
@ -1 +0,0 @@
|
||||
#include <../private/package/hpkg/ZlibDecompressor.h>
|
1
headers/build/private/support/ZlibCompressionBase.h
Normal file
1
headers/build/private/support/ZlibCompressionBase.h
Normal file
@ -0,0 +1 @@
|
||||
#include <../private/support/ZlibCompressionBase.h>
|
1
headers/build/private/support/ZlibCompressor.h
Normal file
1
headers/build/private/support/ZlibCompressor.h
Normal file
@ -0,0 +1 @@
|
||||
#include <../private/support/ZlibCompressor.h>
|
1
headers/build/private/support/ZlibDecompressor.h
Normal file
1
headers/build/private/support/ZlibDecompressor.h
Normal file
@ -0,0 +1 @@
|
||||
#include <../private/support/ZlibDecompressor.h>
|
@ -13,7 +13,6 @@
|
||||
#include <package/hpkg/PackageFileHeapWriter.h>
|
||||
#include <package/hpkg/PackageWriter.h>
|
||||
#include <package/hpkg/Strings.h>
|
||||
#include <package/hpkg/ZlibCompressor.h>
|
||||
|
||||
#include <package/PackageInfo.h>
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ZlibCompressionBase {
|
||||
public:
|
||||
static status_t TranslateZlibError(int error);
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
|
||||
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <package/hpkg/ZlibCompressionBase.h>
|
||||
|
||||
|
||||
class BDataIO;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ZlibCompressor : public ZlibCompressionBase {
|
||||
public:
|
||||
ZlibCompressor(BDataIO* output);
|
||||
~ZlibCompressor();
|
||||
|
||||
status_t Init(int compressionLevel = Z_BEST_COMPRESSION);
|
||||
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 = Z_BEST_COMPRESSION);
|
||||
|
||||
private:
|
||||
z_stream fStream;
|
||||
BDataIO* fOutput;
|
||||
bool fStreamInitialized;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
|
||||
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <package/hpkg/ZlibCompressionBase.h>
|
||||
|
||||
|
||||
class BDataIO;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class ZlibDecompressor : public ZlibCompressionBase {
|
||||
public:
|
||||
ZlibDecompressor(BDataIO* output);
|
||||
~ZlibDecompressor();
|
||||
|
||||
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:
|
||||
z_stream fStream;
|
||||
BDataIO* fOutput;
|
||||
bool fStreamInitialized;
|
||||
bool fFinished;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
|
35
headers/private/support/ZlibCompressionBase.h
Normal file
35
headers/private/support/ZlibCompressionBase.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* 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_
|
43
headers/private/support/ZlibCompressor.h
Normal file
43
headers/private/support/ZlibCompressor.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* 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_
|
32
headers/private/support/ZlibDecompressor.h
Normal file
32
headers/private/support/ZlibDecompressor.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* 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_
|
@ -3,7 +3,7 @@ SubDir HAIKU_TOP src add-ons kernel file_systems packagefs ;
|
||||
|
||||
UseBuildFeatureHeaders zlib ;
|
||||
UsePrivateKernelHeaders ;
|
||||
UsePrivateHeaders package shared storage ;
|
||||
UsePrivateHeaders package shared storage support ;
|
||||
|
||||
|
||||
local subDirs =
|
||||
@ -90,10 +90,6 @@ HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES =
|
||||
PackageFileHeapReader.cpp
|
||||
PackageReaderImpl.cpp
|
||||
ReaderImplBase.cpp
|
||||
|
||||
# compression
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibDecompressor.cpp
|
||||
;
|
||||
|
||||
HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES_V1 =
|
||||
@ -107,15 +103,17 @@ HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES_V1 =
|
||||
ReaderImplBaseV1.cpp
|
||||
;
|
||||
|
||||
Includes
|
||||
[ FGristFiles $(HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES)
|
||||
$(HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES_V1) ]
|
||||
Includes [ FGristFiles ZlibCompressionBasePrivate.h ]
|
||||
: [ BuildFeatureAttribute zlib : headers ] ;
|
||||
|
||||
local libSharedSources =
|
||||
NaturalCompare.cpp
|
||||
;
|
||||
|
||||
local supportKitSources =
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibDecompressor.cpp
|
||||
;
|
||||
|
||||
KernelAddon packagefs
|
||||
:
|
||||
@ -124,6 +122,7 @@ KernelAddon packagefs
|
||||
$(HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES)
|
||||
$(HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES_V1)
|
||||
$(libSharedSources)
|
||||
$(supportKitSources)
|
||||
|
||||
: $(TARGET_KERNEL_LIBSUPC++) kernel_libz.a
|
||||
;
|
||||
@ -137,3 +136,5 @@ SEARCH on [ FGristFiles $(HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES_V1) ]
|
||||
+= [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ;
|
||||
SEARCH on [ FGristFiles $(libSharedSources) ]
|
||||
+= [ FDirName $(HAIKU_TOP) src kits shared ] ;
|
||||
SEARCH on [ FGristFiles $(supportKitSources) ]
|
||||
+= [ FDirName $(HAIKU_TOP) src kits support ] ;
|
||||
|
@ -14,7 +14,7 @@ BuildPlatformSharedLibrary libbe_build.so :
|
||||
<libbe_build>storage_kit.o
|
||||
<libbe_build>support_kit.o
|
||||
|
||||
$(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
|
||||
z $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
|
||||
;
|
||||
|
||||
SubInclude HAIKU_TOP src build libbe app ;
|
||||
|
@ -18,4 +18,7 @@ BuildPlatformMergeObjectPIC <libbe_build>support_kit.o :
|
||||
Referenceable.cpp
|
||||
String.cpp
|
||||
StringList.cpp
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibCompressor.cpp
|
||||
ZlibDecompressor.cpp
|
||||
;
|
||||
|
@ -1,6 +1,6 @@
|
||||
SubDir HAIKU_TOP src build libpackage ;
|
||||
|
||||
UsePrivateBuildHeaders kernel package shared storage ;
|
||||
UsePrivateBuildHeaders kernel package shared storage support ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
|
||||
@ -73,11 +73,6 @@ HPKG_SOURCES =
|
||||
PackageReaderImplV1.cpp
|
||||
PackageReaderV1.cpp
|
||||
ReaderImplBaseV1.cpp
|
||||
|
||||
# compression
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibCompressor.cpp
|
||||
ZlibDecompressor.cpp
|
||||
;
|
||||
|
||||
# TODO: remove this hack once gcc2 has -iquote implemented
|
||||
@ -143,7 +138,7 @@ BuildPlatformSharedLibrary libpackage_build.so
|
||||
SolverRepository.cpp
|
||||
SolverResult.cpp
|
||||
:
|
||||
libshared_build.a $(HOST_LIBBE) curl z $(HOST_LIBSTDC++)
|
||||
libshared_build.a $(HOST_LIBBE) curl $(HOST_LIBSTDC++)
|
||||
;
|
||||
|
||||
HaikuSubInclude solver ;
|
||||
|
@ -45,7 +45,9 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
[ MultiArchDefaultGristFiles libicon.a ]
|
||||
[ MultiArchDefaultGristFiles libagg.a ]
|
||||
|
||||
$(TARGET_LIBSTDC++) [ BuildFeatureAttribute icu : libraries ]
|
||||
$(TARGET_LIBSTDC++)
|
||||
[ BuildFeatureAttribute icu : libraries ]
|
||||
[ BuildFeatureAttribute zlib : library ]
|
||||
;
|
||||
}
|
||||
}
|
||||
@ -71,7 +73,9 @@ SharedLibrary libbe_test.so :
|
||||
[ MultiArchDefaultGristFiles libicon.a ]
|
||||
[ MultiArchDefaultGristFiles libagg.a ]
|
||||
|
||||
$(TARGET_LIBSTDC++) [ BuildFeatureAttribute icu : libraries ]
|
||||
$(TARGET_LIBSTDC++)
|
||||
[ BuildFeatureAttribute icu : libraries ]
|
||||
[ BuildFeatureAttribute zlib : library ]
|
||||
;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) interface ] ;
|
||||
|
@ -5,6 +5,7 @@ UsePrivateHeaders
|
||||
kernel
|
||||
shared
|
||||
storage
|
||||
support
|
||||
;
|
||||
UsePrivateSystemHeaders ;
|
||||
|
||||
@ -54,18 +55,12 @@ HPKG_SOURCES =
|
||||
PackageReaderImplV1.cpp
|
||||
PackageReaderV1.cpp
|
||||
ReaderImplBaseV1.cpp
|
||||
|
||||
# compression
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibCompressor.cpp
|
||||
ZlibDecompressor.cpp
|
||||
;
|
||||
|
||||
local architectureObject ;
|
||||
for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
on $(architectureObject) {
|
||||
UseBuildFeatureHeaders curl ;
|
||||
UseBuildFeatureHeaders zlib ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ;
|
||||
@ -76,8 +71,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
: [ BuildFeatureAttribute curl : headers ] ;
|
||||
Includes [ FGristFiles InitTerminateLibPackage.cpp ]
|
||||
: [ BuildFeatureAttribute curl : headers ] ;
|
||||
Includes [ FGristFiles $(HPKG_SOURCES) ]
|
||||
: [ BuildFeatureAttribute zlib : headers ] ;
|
||||
|
||||
SharedLibrary [ MultiArchDefaultGristFiles libpackage.so ]
|
||||
:
|
||||
@ -139,7 +132,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
[ MultiArchDefaultGristFiles libshared.a ]
|
||||
be
|
||||
[ BuildFeatureAttribute curl : library ]
|
||||
[ BuildFeatureAttribute zlib : library ]
|
||||
$(TARGET_LIBSTDC++)
|
||||
;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
#include <package/hpkg/PackageData.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <package/hpkg/ErrorOutput.h>
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
#include <ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
@ -213,7 +213,7 @@ PackageFileHeapAccessorBase::DecompressChunkData(void* compressedDataBuffer,
|
||||
size_t uncompressedSize)
|
||||
{
|
||||
size_t actualSize;
|
||||
status_t error = ZlibDecompressor::DecompressSingleBuffer(
|
||||
status_t error = BZlibDecompressor::DecompressSingleBuffer(
|
||||
compressedDataBuffer, compressedSize, uncompressedDataBuffer,
|
||||
uncompressedSize, actualSize);
|
||||
if (error != B_OK) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2013-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -16,10 +16,6 @@
|
||||
#include <package/hpkg/PoolBuffer.h>
|
||||
|
||||
|
||||
// minimum length of data we require before trying to zlib compress them
|
||||
static const size_t kZlibCompressionSizeThreshold = 64;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include <AutoDeleter.h>
|
||||
#include <package/hpkg/DataReader.h>
|
||||
#include <package/hpkg/PackageFileHeapReader.h>
|
||||
#include <package/hpkg/ZlibCompressor.h>
|
||||
#include <RangeArray.h>
|
||||
#include <ZlibCompressor.h>
|
||||
|
||||
|
||||
// minimum length of data we require before trying to zlib compress them
|
||||
@ -551,7 +551,7 @@ PackageFileHeapWriter::_WriteDataCompressed(const void* data, size_t size)
|
||||
return B_BUFFER_OVERFLOW;
|
||||
|
||||
size_t compressedSize;
|
||||
status_t error = ZlibCompressor::CompressSingleBuffer(data, size,
|
||||
status_t error = BZlibCompressor::CompressSingleBuffer(data, size,
|
||||
fCompressedDataBuffer, size, compressedSize, fCompressionLevel);
|
||||
if (error != B_OK) {
|
||||
if (error != B_BUFFER_OVERFLOW) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
@ -25,7 +25,6 @@
|
||||
#include <package/hpkg/PackageData.h>
|
||||
#include <package/hpkg/PackageEntry.h>
|
||||
#include <package/hpkg/PackageEntryAttribute.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
@ -58,10 +58,6 @@ namespace BHPKG {
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
// minimum length of data we require before trying to zlib compress them
|
||||
static const size_t kZlibCompressionSizeThreshold = 64;
|
||||
|
||||
|
||||
// #pragma mark - Attributes
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
@ -21,7 +22,7 @@
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/PackageFileHeapReader.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
#include <ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <package/hpkg/ZlibCompressionBase.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
ZlibCompressionBase::TranslateZlibError(int error)
|
||||
{
|
||||
switch (error) {
|
||||
case Z_OK:
|
||||
return B_OK;
|
||||
case Z_STREAM_END:
|
||||
case Z_NEED_DICT:
|
||||
// a special event (no error), but the caller doesn't seem to handle
|
||||
// it
|
||||
return B_ERROR;
|
||||
case Z_ERRNO:
|
||||
return errno;
|
||||
case Z_STREAM_ERROR:
|
||||
return B_BAD_VALUE;
|
||||
case Z_DATA_ERROR:
|
||||
return B_BAD_DATA;
|
||||
case Z_MEM_ERROR:
|
||||
return B_NO_MEMORY;
|
||||
case Z_BUF_ERROR:
|
||||
return B_BUFFER_OVERFLOW;
|
||||
case Z_VERSION_ERROR:
|
||||
return B_BAD_VALUE;
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <package/hpkg/ZlibCompressor.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
static const size_t kOutputBufferSize = 1024;
|
||||
|
||||
|
||||
ZlibCompressor::ZlibCompressor(BDataIO* output)
|
||||
:
|
||||
fOutput(output),
|
||||
fStreamInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZlibCompressor::~ZlibCompressor()
|
||||
{
|
||||
if (fStreamInitialized)
|
||||
deflateEnd(&fStream);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibCompressor::Init(int compressionLevel)
|
||||
{
|
||||
// initialize the stream
|
||||
fStream.next_in = NULL;
|
||||
fStream.avail_in = 0;
|
||||
fStream.total_in = 0;
|
||||
fStream.next_out = NULL;
|
||||
fStream.avail_out = 0;
|
||||
fStream.total_out = 0;
|
||||
fStream.msg = 0;
|
||||
fStream.state = 0;
|
||||
fStream.zalloc = Z_NULL;
|
||||
fStream.zfree = Z_NULL;
|
||||
fStream.opaque = Z_NULL;
|
||||
fStream.data_type = 0;
|
||||
fStream.adler = 0;
|
||||
fStream.reserved = 0;
|
||||
|
||||
int zlibError = deflateInit(&fStream, compressionLevel);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
fStreamInitialized = true;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibCompressor::CompressNext(const void* input, size_t inputSize)
|
||||
{
|
||||
fStream.next_in = (Bytef*)input;
|
||||
fStream.avail_in = inputSize;
|
||||
|
||||
while (fStream.avail_in > 0) {
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream.next_out = (Bytef*)outputBuffer;
|
||||
fStream.avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = deflate(&fStream, 0);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream.avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream.avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibCompressor::Finish()
|
||||
{
|
||||
fStream.next_in = (Bytef*)NULL;
|
||||
fStream.avail_in = 0;
|
||||
|
||||
while (true) {
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream.next_out = (Bytef*)outputBuffer;
|
||||
fStream.avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = deflate(&fStream, Z_FINISH);
|
||||
if (zlibError != Z_OK && zlibError != Z_STREAM_END)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream.avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream.avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
|
||||
if (zlibError == Z_STREAM_END)
|
||||
break;
|
||||
}
|
||||
|
||||
deflateEnd(&fStream);
|
||||
fStreamInitialized = false;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
ZlibCompressor::CompressSingleBuffer(const void* input, size_t inputSize,
|
||||
void* output, size_t outputSize, size_t& _compressedSize,
|
||||
int compressionLevel)
|
||||
{
|
||||
if (inputSize == 0 || outputSize == 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// prepare stream
|
||||
z_stream zStream = {
|
||||
(Bytef*)input, // next_in
|
||||
uInt(inputSize), // avail_in
|
||||
0, // total_in
|
||||
(Bytef*)output, // next_out
|
||||
uInt(outputSize), // avail_out
|
||||
0, // total_out
|
||||
0, // msg
|
||||
0, // state;
|
||||
Z_NULL, // zalloc
|
||||
Z_NULL, // zfree
|
||||
Z_NULL, // opaque
|
||||
0, // data_type
|
||||
0, // adler
|
||||
0 // reserved
|
||||
};
|
||||
|
||||
int zlibError = deflateInit(&zStream, compressionLevel);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
// deflate
|
||||
status_t error = B_OK;
|
||||
zlibError = deflate(&zStream, Z_FINISH);
|
||||
if (zlibError != Z_STREAM_END) {
|
||||
if (zlibError == Z_OK)
|
||||
error = B_BUFFER_OVERFLOW;
|
||||
else
|
||||
error = TranslateZlibError(zlibError);
|
||||
}
|
||||
|
||||
// clean up
|
||||
zlibError = deflateEnd(&zStream);
|
||||
if (zlibError != Z_OK && error == B_OK)
|
||||
error = TranslateZlibError(zlibError);
|
||||
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
_compressedSize = zStream.total_out;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
// TODO: For the kernel the buffer shouldn't be allocated on the stack.
|
||||
static const size_t kOutputBufferSize = 1024;
|
||||
|
||||
|
||||
ZlibDecompressor::ZlibDecompressor(BDataIO* output)
|
||||
:
|
||||
fOutput(output),
|
||||
fStreamInitialized(false),
|
||||
fFinished(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZlibDecompressor::~ZlibDecompressor()
|
||||
{
|
||||
if (fStreamInitialized)
|
||||
inflateEnd(&fStream);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibDecompressor::Init()
|
||||
{
|
||||
// initialize the stream
|
||||
fStream.next_in = NULL;
|
||||
fStream.avail_in = 0;
|
||||
fStream.total_in = 0;
|
||||
fStream.next_out = NULL;
|
||||
fStream.avail_out = 0;
|
||||
fStream.total_out = 0;
|
||||
fStream.msg = 0;
|
||||
fStream.state = 0;
|
||||
fStream.zalloc = Z_NULL;
|
||||
fStream.zfree = Z_NULL;
|
||||
fStream.opaque = Z_NULL;
|
||||
fStream.data_type = 0;
|
||||
fStream.adler = 0;
|
||||
fStream.reserved = 0;
|
||||
|
||||
int zlibError = inflateInit(&fStream);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
fStreamInitialized = true;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibDecompressor::DecompressNext(const void* input, size_t inputSize)
|
||||
{
|
||||
fStream.next_in = (Bytef*)input;
|
||||
fStream.avail_in = inputSize;
|
||||
|
||||
while (fStream.avail_in > 0) {
|
||||
if (fFinished)
|
||||
return B_BAD_DATA;
|
||||
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream.next_out = (Bytef*)outputBuffer;
|
||||
fStream.avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = inflate(&fStream, 0);
|
||||
if (zlibError == Z_STREAM_END)
|
||||
fFinished = true;
|
||||
else if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream.avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream.avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibDecompressor::Finish()
|
||||
{
|
||||
fStream.next_in = (Bytef*)NULL;
|
||||
fStream.avail_in = 0;
|
||||
|
||||
while (!fFinished) {
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream.next_out = (Bytef*)outputBuffer;
|
||||
fStream.avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = inflate(&fStream, Z_FINISH);
|
||||
if (zlibError == Z_STREAM_END)
|
||||
fFinished = true;
|
||||
else if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream.avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream.avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
inflateEnd(&fStream);
|
||||
fStreamInitialized = false;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
ZlibDecompressor::DecompressSingleBuffer(const void* input, size_t inputSize,
|
||||
void* output, size_t outputSize, size_t& _uncompressedSize)
|
||||
{
|
||||
if (inputSize == 0 || outputSize == 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// prepare stream
|
||||
z_stream zStream = {
|
||||
(Bytef*)input, // next_in
|
||||
uInt(inputSize), // avail_in
|
||||
0, // total_in
|
||||
(Bytef*)output, // next_out
|
||||
uInt(outputSize), // avail_out
|
||||
0, // total_out
|
||||
0, // msg
|
||||
0, // state;
|
||||
Z_NULL, // zalloc
|
||||
Z_NULL, // zfree
|
||||
Z_NULL, // opaque
|
||||
0, // data_type
|
||||
0, // adler
|
||||
0 // reserved
|
||||
};
|
||||
|
||||
int zlibError = inflateInit(&zStream);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
|
||||
// inflate
|
||||
status_t error = B_OK;
|
||||
zlibError = inflate(&zStream, Z_FINISH);
|
||||
if (zlibError != Z_STREAM_END) {
|
||||
if (zlibError == Z_OK)
|
||||
error = B_BUFFER_OVERFLOW;
|
||||
else
|
||||
error = TranslateZlibError(zlibError);
|
||||
}
|
||||
|
||||
// clean up
|
||||
zlibError = inflateEnd(&zStream);
|
||||
if (zlibError != Z_OK && error == B_OK)
|
||||
error = TranslateZlibError(zlibError);
|
||||
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
_uncompressedSize = zStream.total_out;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
@ -16,7 +16,7 @@
|
||||
#include <package/hpkg/PoolBuffer.h>
|
||||
#include <package/hpkg/v1/HPKGDefsPrivate.h>
|
||||
#include <package/hpkg/v1/PackageData.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
#include <ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
@ -27,7 +27,6 @@ namespace V1 {
|
||||
|
||||
|
||||
using BHPKG::BPrivate::PoolBufferPutter;
|
||||
using BHPKG::BPrivate::ZlibDecompressor;
|
||||
|
||||
|
||||
// minimum/maximum zlib chunk size we consider sane
|
||||
@ -295,7 +294,7 @@ private:
|
||||
return error;
|
||||
|
||||
size_t actuallyUncompressedSize;
|
||||
error = ZlibDecompressor::DecompressSingleBuffer(
|
||||
error = BZlibDecompressor::DecompressSingleBuffer(
|
||||
readBuffer->Buffer(), compressedSize,
|
||||
fUncompressBuffer->Buffer(), uncompressedSize,
|
||||
actuallyUncompressedSize);
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <package/hpkg/v1/PackageData.h>
|
||||
#include <package/hpkg/v1/PackageEntry.h>
|
||||
#include <package/hpkg/v1/PackageEntryAttribute.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
@ -21,7 +22,7 @@
|
||||
#include <package/hpkg/v1/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/ErrorOutput.h>
|
||||
#include <package/hpkg/ZlibDecompressor.h>
|
||||
#include <ZlibDecompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
@ -33,9 +34,6 @@ namespace V1 {
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
using BHPKG::BPrivate::ZlibDecompressor;
|
||||
|
||||
|
||||
static const size_t kScratchBufferSize = 64 * 1024;
|
||||
|
||||
|
||||
@ -1032,7 +1030,7 @@ ReaderImplBase::ReadCompressedBuffer(const SectionInfo& section)
|
||||
{
|
||||
// init the decompressor
|
||||
BMemoryIO bufferOutput(section.data, section.uncompressedLength);
|
||||
ZlibDecompressor decompressor(&bufferOutput);
|
||||
BZlibDecompressor decompressor(&bufferOutput);
|
||||
status_t error = decompressor.Init();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
@ -9,6 +9,11 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
on $(architectureObject) {
|
||||
local architecture = $(TARGET_PACKAGING_ARCH) ;
|
||||
|
||||
UseBuildFeatureHeaders zlib ;
|
||||
|
||||
Includes [ FGristFiles ZlibCompressionBasePrivate.h ]
|
||||
: [ BuildFeatureAttribute zlib : headers ] ;
|
||||
|
||||
MergeObject <libbe!$(architecture)>support_kit.o :
|
||||
Architecture.cpp
|
||||
Archivable.cpp
|
||||
@ -31,6 +36,9 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
StringList.cpp
|
||||
Url.cpp
|
||||
Uuid.cpp
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibCompressor.cpp
|
||||
ZlibDecompressor.cpp
|
||||
;
|
||||
|
||||
StaticLibrary [ MultiArchDefaultGristFiles libreferenceable.a ]
|
||||
|
80
src/kits/support/ZlibCompressionBase.cpp
Normal file
80
src/kits/support/ZlibCompressionBase.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <ZlibCompressionBase.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include "ZlibCompressionBasePrivate.h"
|
||||
|
||||
|
||||
BZlibCompressionBase::BZlibCompressionBase(BDataIO* output)
|
||||
:
|
||||
fOutput(output),
|
||||
fStream(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BZlibCompressionBase::~BZlibCompressionBase()
|
||||
{
|
||||
DeleteStream();
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
BZlibCompressionBase::TranslateZlibError(int error)
|
||||
{
|
||||
switch (error) {
|
||||
case Z_OK:
|
||||
return B_OK;
|
||||
case Z_STREAM_END:
|
||||
case Z_NEED_DICT:
|
||||
// a special event (no error), but the caller doesn't seem to handle
|
||||
// it
|
||||
return B_ERROR;
|
||||
case Z_ERRNO:
|
||||
return errno;
|
||||
case Z_STREAM_ERROR:
|
||||
return B_BAD_VALUE;
|
||||
case Z_DATA_ERROR:
|
||||
return B_BAD_DATA;
|
||||
case Z_MEM_ERROR:
|
||||
return B_NO_MEMORY;
|
||||
case Z_BUF_ERROR:
|
||||
return B_BUFFER_OVERFLOW;
|
||||
case Z_VERSION_ERROR:
|
||||
return B_BAD_VALUE;
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibCompressionBase::CreateStream()
|
||||
{
|
||||
if (fStream != NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
fStream = new(std::nothrow) ZStream;
|
||||
if (fStream == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
memset(fStream, 0, sizeof(*fStream));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BZlibCompressionBase::DeleteStream()
|
||||
{
|
||||
delete fStream;
|
||||
fStream = NULL;
|
||||
}
|
16
src/kits/support/ZlibCompressionBasePrivate.h
Normal file
16
src/kits/support/ZlibCompressionBasePrivate.h
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ZLIB_COMPRESSION_BASE_PRIVATE_H
|
||||
#define ZLIB_COMPRESSION_BASE_PRIVATE_H
|
||||
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
struct BZlibCompressionBase::ZStream : z_stream {
|
||||
};
|
||||
|
||||
|
||||
#endif // ZLIB_COMPRESSION_BASE_PRIVATE_H
|
150
src/kits/support/ZlibCompressor.cpp
Normal file
150
src/kits/support/ZlibCompressor.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <ZlibCompressor.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
#include "ZlibCompressionBasePrivate.h"
|
||||
|
||||
|
||||
static const size_t kOutputBufferSize = 1024;
|
||||
|
||||
|
||||
BZlibCompressor::BZlibCompressor(BDataIO* output)
|
||||
:
|
||||
BZlibCompressionBase(output)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BZlibCompressor::~BZlibCompressor()
|
||||
{
|
||||
if (fStream != NULL)
|
||||
deflateEnd(fStream);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibCompressor::Init(int compressionLevel)
|
||||
{
|
||||
status_t error = CreateStream();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
int zlibError = deflateInit(fStream, compressionLevel);
|
||||
if (zlibError != Z_OK) {
|
||||
DeleteStream();
|
||||
return TranslateZlibError(zlibError);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibCompressor::CompressNext(const void* input, size_t inputSize)
|
||||
{
|
||||
fStream->next_in = (Bytef*)input;
|
||||
fStream->avail_in = inputSize;
|
||||
|
||||
while (fStream->avail_in > 0) {
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream->next_out = (Bytef*)outputBuffer;
|
||||
fStream->avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = deflate(fStream, 0);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream->avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream->avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibCompressor::Finish()
|
||||
{
|
||||
fStream->next_in = (Bytef*)NULL;
|
||||
fStream->avail_in = 0;
|
||||
|
||||
while (true) {
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream->next_out = (Bytef*)outputBuffer;
|
||||
fStream->avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = deflate(fStream, Z_FINISH);
|
||||
if (zlibError != Z_OK && zlibError != Z_STREAM_END)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream->avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream->avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
|
||||
if (zlibError == Z_STREAM_END)
|
||||
break;
|
||||
}
|
||||
|
||||
deflateEnd(fStream);
|
||||
DeleteStream();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
BZlibCompressor::CompressSingleBuffer(const void* input, size_t inputSize,
|
||||
void* output, size_t outputSize, size_t& _compressedSize,
|
||||
int compressionLevel)
|
||||
{
|
||||
if (inputSize == 0 || outputSize == 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// prepare stream
|
||||
z_stream zStream;
|
||||
memset(&zStream, 0, sizeof(zStream));
|
||||
zStream.next_in = (Bytef*)input;
|
||||
zStream.avail_in = uInt(inputSize);
|
||||
zStream.next_out = (Bytef*)output;
|
||||
zStream.avail_out = uInt(outputSize);
|
||||
|
||||
int zlibError = deflateInit(&zStream, compressionLevel);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
// deflate
|
||||
status_t error = B_OK;
|
||||
zlibError = deflate(&zStream, Z_FINISH);
|
||||
if (zlibError != Z_STREAM_END) {
|
||||
if (zlibError == Z_OK)
|
||||
error = B_BUFFER_OVERFLOW;
|
||||
else
|
||||
error = TranslateZlibError(zlibError);
|
||||
}
|
||||
|
||||
// clean up
|
||||
zlibError = deflateEnd(&zStream);
|
||||
if (zlibError != Z_OK && error == B_OK)
|
||||
error = TranslateZlibError(zlibError);
|
||||
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
_compressedSize = zStream.total_out;
|
||||
return B_OK;
|
||||
}
|
155
src/kits/support/ZlibDecompressor.cpp
Normal file
155
src/kits/support/ZlibDecompressor.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <ZlibDecompressor.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <DataIO.h>
|
||||
|
||||
#include "ZlibCompressionBasePrivate.h"
|
||||
|
||||
|
||||
// TODO: For the kernel the buffer shouldn't be allocated on the stack.
|
||||
static const size_t kOutputBufferSize = 1024;
|
||||
|
||||
|
||||
BZlibDecompressor::BZlibDecompressor(BDataIO* output)
|
||||
:
|
||||
BZlibCompressionBase(output),
|
||||
fFinished(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BZlibDecompressor::~BZlibDecompressor()
|
||||
{
|
||||
if (fStream != NULL)
|
||||
inflateEnd(fStream);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibDecompressor::Init()
|
||||
{
|
||||
status_t error = CreateStream();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
int zlibError = inflateInit(fStream);
|
||||
if (zlibError != Z_OK) {
|
||||
DeleteStream();
|
||||
return TranslateZlibError(zlibError);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibDecompressor::DecompressNext(const void* input, size_t inputSize)
|
||||
{
|
||||
fStream->next_in = (Bytef*)input;
|
||||
fStream->avail_in = inputSize;
|
||||
|
||||
while (fStream->avail_in > 0) {
|
||||
if (fFinished)
|
||||
return B_BAD_DATA;
|
||||
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream->next_out = (Bytef*)outputBuffer;
|
||||
fStream->avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = inflate(fStream, 0);
|
||||
if (zlibError == Z_STREAM_END)
|
||||
fFinished = true;
|
||||
else if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream->avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream->avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BZlibDecompressor::Finish()
|
||||
{
|
||||
fStream->next_in = (Bytef*)NULL;
|
||||
fStream->avail_in = 0;
|
||||
|
||||
while (!fFinished) {
|
||||
uint8 outputBuffer[kOutputBufferSize];
|
||||
fStream->next_out = (Bytef*)outputBuffer;
|
||||
fStream->avail_out = sizeof(outputBuffer);
|
||||
|
||||
int zlibError = inflate(fStream, Z_FINISH);
|
||||
if (zlibError == Z_STREAM_END)
|
||||
fFinished = true;
|
||||
else if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
if (fStream->avail_out < sizeof(outputBuffer)) {
|
||||
status_t error = fOutput->WriteExactly(outputBuffer,
|
||||
sizeof(outputBuffer) - fStream->avail_out);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
inflateEnd(fStream);
|
||||
DeleteStream();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
BZlibDecompressor::DecompressSingleBuffer(const void* input, size_t inputSize,
|
||||
void* output, size_t outputSize, size_t& _uncompressedSize)
|
||||
{
|
||||
if (inputSize == 0 || outputSize == 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// prepare stream
|
||||
z_stream zStream;
|
||||
memset(&zStream, 0, sizeof(zStream));
|
||||
zStream.next_in = (Bytef*)input;
|
||||
zStream.avail_in = uInt(inputSize);
|
||||
zStream.next_out = (Bytef*)output;
|
||||
zStream.avail_out = uInt(outputSize);
|
||||
|
||||
int zlibError = inflateInit(&zStream);
|
||||
if (zlibError != Z_OK)
|
||||
return TranslateZlibError(zlibError);
|
||||
|
||||
// inflate
|
||||
status_t error = B_OK;
|
||||
zlibError = inflate(&zStream, Z_FINISH);
|
||||
if (zlibError != Z_STREAM_END) {
|
||||
if (zlibError == Z_OK)
|
||||
error = B_BUFFER_OVERFLOW;
|
||||
else
|
||||
error = TranslateZlibError(zlibError);
|
||||
}
|
||||
|
||||
// clean up
|
||||
zlibError = inflateEnd(&zStream);
|
||||
if (zlibError != Z_OK && error == B_OK)
|
||||
error = TranslateZlibError(zlibError);
|
||||
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
_uncompressedSize = zStream.total_out;
|
||||
return B_OK;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
SubDir HAIKU_TOP src system boot loader file_systems packagefs ;
|
||||
|
||||
UsePrivateHeaders [ FDirName kernel boot platform $(TARGET_BOOT_PLATFORM) ] ;
|
||||
UsePrivateHeaders kernel shared ;
|
||||
UsePrivateHeaders kernel shared support ;
|
||||
UseBuildFeatureHeaders zlib ;
|
||||
|
||||
DEFINES += _BOOT_MODE ;
|
||||
@ -13,6 +13,7 @@ SubDirC++Flags -fno-rtti -include $(kernelC++Header) ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits support ] ;
|
||||
|
||||
|
||||
BootStaticLibrary boot_packagefs :
|
||||
@ -40,16 +41,14 @@ BootStaticLibrary boot_packagefs :
|
||||
PackageReaderImpl.cpp
|
||||
ReaderImplBase.cpp
|
||||
|
||||
# compression
|
||||
# support kit
|
||||
|
||||
ZlibCompressionBase.cpp
|
||||
ZlibDecompressor.cpp
|
||||
|
||||
: -fno-pic
|
||||
;
|
||||
|
||||
Includes [
|
||||
FGristFiles ZlibCompressionBase.cpp package/hpkg/ZlibCompressor.h
|
||||
package/hpkg/ZlibDecompressor.h
|
||||
]
|
||||
Includes [ FGristFiles ZlibCompressionBasePrivate.h ]
|
||||
: [ BuildFeatureAttribute zlib : headers ] ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user