From fd9c0b33616cfc25e833baa6e4a51deeee366634 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 4 Feb 2011 22:40:10 +0000 Subject: [PATCH] * added support for compressing the package attributes section to PackageWriterImpl * added my own copyright git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40358 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../private/package/hpkg/PackageWriterImpl.h | 1 + src/kits/package/hpkg/PackageWriterImpl.cpp | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/headers/private/package/hpkg/PackageWriterImpl.h b/headers/private/package/hpkg/PackageWriterImpl.h index f0fd9721f4..23b5553232 100644 --- a/headers/private/package/hpkg/PackageWriterImpl.h +++ b/headers/private/package/hpkg/PackageWriterImpl.h @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ #ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_ diff --git a/src/kits/package/hpkg/PackageWriterImpl.cpp b/src/kits/package/hpkg/PackageWriterImpl.cpp index 5d9e02d2f8..4dac7ae6bb 100644 --- a/src/kits/package/hpkg/PackageWriterImpl.cpp +++ b/src/kits/package/hpkg/PackageWriterImpl.cpp @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ @@ -1006,10 +1007,12 @@ PackageWriterImpl::_WriteAttributeChildren(Attribute* attribute) void PackageWriterImpl::_WritePackageAttributes(hpkg_header& header) { - // write the package attributes + // write the package attributes (zlib writer on top of a file writer) off_t startOffset = fHeapEnd; FDDataWriter realWriter(fFD, startOffset, fListener); - fDataWriter = &realWriter; + ZlibDataWriter zlibWriter(&realWriter); + fDataWriter = &zlibWriter; + zlibWriter.Init(); // name _WriteUnsignedLEB128(B_HPKG_PACKAGE_ATTRIBUTE_TAG_COMPOSE( @@ -1114,21 +1117,22 @@ PackageWriterImpl::_WritePackageAttributes(hpkg_header& header) } _Write(0); + + zlibWriter.Finish(); fHeapEnd = realWriter.Offset(); fDataWriter = NULL; off_t endOffset = fHeapEnd; - fListener->OnPackageAttributesSizeInfo(endOffset - startOffset); + fListener->OnPackageAttributesSizeInfo(zlibWriter.BytesWritten()); // update the header - header.attributes_compression = B_HOST_TO_BENDIAN_INT32( - B_HPKG_COMPRESSION_NONE); + header.attributes_compression + = B_HOST_TO_BENDIAN_INT32(B_HPKG_COMPRESSION_ZLIB); header.attributes_length_compressed = B_HOST_TO_BENDIAN_INT32(endOffset - startOffset); header.attributes_length_uncompressed - = header.attributes_length_compressed; - // TODO: Support compression! + = B_HOST_TO_BENDIAN_INT32(zlibWriter.BytesWritten()); }