Remove BPackageKit::BDataOutput

Use BDataIO instead.
This commit is contained in:
Ingo Weinhold
2014-06-23 22:58:15 +02:00
parent 0d8b44e25b
commit 32832cbe47
32 changed files with 102 additions and 211 deletions
@@ -1 +0,0 @@
#include <../os/package/hpkg/DataOutput.h>
-45
View File
@@ -1,45 +0,0 @@
/*
* Copyright 2009,2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__DATA_OUTPUT_H_
#define _PACKAGE__HPKG__DATA_OUTPUT_H_
#include <SupportDefs.h>
namespace BPackageKit {
namespace BHPKG {
class BDataOutput {
public:
virtual ~BDataOutput();
virtual status_t WriteData(const void* buffer, size_t size) = 0;
};
class BBufferDataOutput : public BDataOutput {
public:
BBufferDataOutput(void* buffer, size_t size);
size_t BytesWritten() const { return fBytesWritten; }
virtual status_t WriteData(const void* buffer, size_t size);
private:
void* fBuffer;
size_t fSize;
size_t fBytesWritten;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__DATA_OUTPUT_H_
+6 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009,2011, Haiku, Inc. * Copyright 2009-2014, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__HPKG__DATA_READER_H_ #ifndef _PACKAGE__HPKG__DATA_READER_H_
@@ -9,14 +9,14 @@
#include <SupportDefs.h> #include <SupportDefs.h>
class BDataIO;
namespace BPackageKit { namespace BPackageKit {
namespace BHPKG { namespace BHPKG {
class BDataOutput;
class BDataReader { class BDataReader {
public: public:
virtual ~BDataReader(); virtual ~BDataReader();
@@ -33,7 +33,7 @@ public:
virtual status_t ReadData(off_t offset, void* buffer, virtual status_t ReadData(off_t offset, void* buffer,
size_t size); size_t size);
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) = 0; BDataIO* output) = 0;
}; };
@@ -73,7 +73,7 @@ public:
virtual status_t ReadData(off_t offset, void* buffer, virtual status_t ReadData(off_t offset, void* buffer,
size_t size); size_t size);
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output); BDataIO* output);
private: private:
const void* fData; const void* fData;
+5 -5
View File
@@ -1,13 +1,13 @@
/* /*
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Copyright 2013, Ingo Weinhold, [email protected]. * Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_ #ifndef _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
#define _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_ #define _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
#include <package/hpkg/DataOutput.h> #include <DataIO.h>
#include <package/hpkg/ZlibCompressor.h> #include <package/hpkg/ZlibCompressor.h>
@@ -59,7 +59,7 @@ private:
}; };
class ZlibDataWriter : public AbstractDataWriter, private BDataOutput { class ZlibDataWriter : public AbstractDataWriter, private BDataIO {
public: public:
ZlibDataWriter(AbstractDataWriter* dataWriter); ZlibDataWriter(AbstractDataWriter* dataWriter);
@@ -70,8 +70,8 @@ public:
size_t size); size_t size);
private: private:
// BDataOutput // BDataIO
virtual status_t WriteData(const void* buffer, size_t size); virtual ssize_t Write(const void* buffer, size_t size);
private: private:
AbstractDataWriter* fDataWriter; AbstractDataWriter* fDataWriter;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2013, Ingo Weinhold, [email protected]. * Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_ACCESSOR_BASE_H_ #ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_FILE_HEAP_ACCESSOR_BASE_H_
@@ -48,8 +48,8 @@ public:
{ fFD = fd; } { fFD = fd; }
// BAbstractBufferedDataReader // BAbstractBufferedDataReader
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset,
BDataOutput* output); size_t size, BDataIO* output);
public: public:
static const size_t kChunkSize = 64 * 1024; static const size_t kChunkSize = 64 * 1024;
@@ -10,7 +10,6 @@
#include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/HPKGDefsPrivate.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/DataWriters.h> #include <package/hpkg/DataWriters.h>
#include <package/hpkg/PackageWriter.h> #include <package/hpkg/PackageWriter.h>
#include <package/hpkg/Strings.h> #include <package/hpkg/Strings.h>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_ #ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
@@ -11,20 +11,19 @@
#include <package/hpkg/ZlibCompressionBase.h> #include <package/hpkg/ZlibCompressionBase.h>
class BDataIO;
namespace BPackageKit { namespace BPackageKit {
namespace BHPKG { namespace BHPKG {
class BDataOutput;
namespace BPrivate { namespace BPrivate {
class ZlibCompressor : public ZlibCompressionBase { class ZlibCompressor : public ZlibCompressionBase {
public: public:
ZlibCompressor(BDataOutput* output); ZlibCompressor(BDataIO* output);
~ZlibCompressor(); ~ZlibCompressor();
status_t Init(int compressionLevel = Z_BEST_COMPRESSION); status_t Init(int compressionLevel = Z_BEST_COMPRESSION);
@@ -39,7 +38,7 @@ public:
private: private:
z_stream fStream; z_stream fStream;
BDataOutput* fOutput; BDataIO* fOutput;
bool fStreamInitialized; bool fStreamInitialized;
}; };
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_ #ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
@@ -11,20 +11,19 @@
#include <package/hpkg/ZlibCompressionBase.h> #include <package/hpkg/ZlibCompressionBase.h>
class BDataIO;
namespace BPackageKit { namespace BPackageKit {
namespace BHPKG { namespace BHPKG {
class BDataOutput;
namespace BPrivate { namespace BPrivate {
class ZlibDecompressor : public ZlibCompressionBase { class ZlibDecompressor : public ZlibCompressionBase {
public: public:
ZlibDecompressor(BDataOutput* output); ZlibDecompressor(BDataIO* output);
~ZlibDecompressor(); ~ZlibDecompressor();
status_t Init(); status_t Init();
@@ -39,7 +38,7 @@ public:
private: private:
z_stream fStream; z_stream fStream;
BDataOutput* fOutput; BDataIO* fOutput;
bool fStreamInitialized; bool fStreamInitialized;
bool fFinished; bool fFinished;
}; };
@@ -76,7 +76,6 @@ HAIKU_PACKAGE_FS_SHARED_SOURCES =
HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES = HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES =
BlockBufferPoolImpl.cpp BlockBufferPoolImpl.cpp
BufferPool.cpp BufferPool.cpp
DataOutput.cpp
DataReader.cpp DataReader.cpp
ErrorOutput.cpp ErrorOutput.cpp
FDDataReader.cpp FDDataReader.cpp
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2013, Ingo Weinhold, [email protected]. * Copyright 2010-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -8,7 +8,7 @@
#include <algorithm> #include <algorithm>
#include <package/hpkg/DataOutput.h> #include <DataIO.h>
#include <util/AutoLock.h> #include <util/AutoLock.h>
#include <vm/VMCache.h> #include <vm/VMCache.h>
@@ -18,7 +18,6 @@
using BPackageKit::BHPKG::BBufferDataReader; using BPackageKit::BHPKG::BBufferDataReader;
using BPackageKit::BHPKG::BBufferDataOutput;
static inline bool static inline bool
@@ -31,7 +30,7 @@ page_physical_number_less(const vm_page* a, const vm_page* b)
// #pragma mark - PagesDataOutput // #pragma mark - PagesDataOutput
struct CachedDataReader::PagesDataOutput : public BDataOutput { struct CachedDataReader::PagesDataOutput : public BDataIO {
PagesDataOutput(vm_page** pages, size_t pageCount) PagesDataOutput(vm_page** pages, size_t pageCount)
: :
fPages(pages), fPages(pages),
@@ -40,13 +39,15 @@ struct CachedDataReader::PagesDataOutput : public BDataOutput {
{ {
} }
virtual status_t WriteData(const void* buffer, size_t size) virtual ssize_t Write(const void* buffer, size_t size)
{ {
while (size > 0) { size_t bytesRemaining = size;
while (bytesRemaining > 0) {
if (fPageCount == 0) if (fPageCount == 0)
return B_BAD_VALUE; return B_BAD_VALUE;
size_t toCopy = std::min(size, B_PAGE_SIZE - fInPageOffset); size_t toCopy = std::min(bytesRemaining,
B_PAGE_SIZE - fInPageOffset);
status_t error = vm_memcpy_to_physical( status_t error = vm_memcpy_to_physical(
fPages[0]->physical_page_number * B_PAGE_SIZE + fInPageOffset, fPages[0]->physical_page_number * B_PAGE_SIZE + fInPageOffset,
buffer, toCopy, false); buffer, toCopy, false);
@@ -61,10 +62,10 @@ struct CachedDataReader::PagesDataOutput : public BDataOutput {
} }
buffer = (const char*)buffer + toCopy; buffer = (const char*)buffer + toCopy;
size -= toCopy; bytesRemaining -= toCopy;
} }
return B_OK; return size;
} }
private: private:
@@ -125,14 +126,14 @@ CachedDataReader::Init(BAbstractBufferedDataReader* reader, off_t size)
status_t status_t
CachedDataReader::ReadData(off_t offset, void* buffer, size_t size) CachedDataReader::ReadData(off_t offset, void* buffer, size_t size)
{ {
BBufferDataOutput output(buffer, size); BMemoryIO output(buffer, size);
return ReadDataToOutput(offset, size, &output); return ReadDataToOutput(offset, size, &output);
} }
status_t status_t
CachedDataReader::ReadDataToOutput(off_t offset, size_t size, CachedDataReader::ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) BDataIO* output)
{ {
if (offset > fCache->virtual_end if (offset > fCache->virtual_end
|| (off_t)size > fCache->virtual_end - offset) { || (off_t)size > fCache->virtual_end - offset) {
@@ -168,7 +169,7 @@ CachedDataReader::ReadDataToOutput(off_t offset, size_t size,
status_t status_t
CachedDataReader::_ReadCacheLine(off_t lineOffset, size_t lineSize, CachedDataReader::_ReadCacheLine(off_t lineOffset, size_t lineSize,
off_t requestOffset, size_t requestLength, BDataOutput* output) off_t requestOffset, size_t requestLength, BDataIO* output)
{ {
PRINT("CachedDataReader::_ReadCacheLine(%" B_PRIdOFF ", %zu, %" B_PRIdOFF PRINT("CachedDataReader::_ReadCacheLine(%" B_PRIdOFF ", %zu, %" B_PRIdOFF
", %zu, %p\n", lineOffset, lineSize, requestOffset, requestLength, ", %zu, %p\n", lineOffset, lineSize, requestOffset, requestLength,
@@ -366,7 +367,7 @@ CachedDataReader::_CachePages(vm_page** pages, size_t firstPage,
*/ */
status_t status_t
CachedDataReader::_WritePages(vm_page** pages, size_t pagesRelativeOffset, CachedDataReader::_WritePages(vm_page** pages, size_t pagesRelativeOffset,
size_t requestLength, BDataOutput* output) size_t requestLength, BDataIO* output)
{ {
PRINT("%p->CachedDataReader::_WritePages(%" B_PRIuSIZE ", %" B_PRIuSIZE PRINT("%p->CachedDataReader::_WritePages(%" B_PRIuSIZE ", %" B_PRIuSIZE
", %p)\n", this, pagesRelativeOffset, requestLength, output); ", %p)\n", this, pagesRelativeOffset, requestLength, output);
@@ -389,7 +390,7 @@ CachedDataReader::_WritePages(vm_page** pages, size_t pagesRelativeOffset,
// write the page's data // write the page's data
size_t toCopy = std::min(B_PAGE_SIZE - inPageOffset, requestLength); size_t toCopy = std::min(B_PAGE_SIZE - inPageOffset, requestLength);
error = output->WriteData((uint8*)(address + inPageOffset), toCopy); error = output->WriteExactly((uint8*)(address + inPageOffset), toCopy);
// unmap the page // unmap the page
vm_put_physical_page(address, handle); vm_put_physical_page(address, handle);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2013, Ingo Weinhold, [email protected]. * Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef HEAP_CACHE_H #ifndef HEAP_CACHE_H
@@ -15,7 +15,6 @@
using BPackageKit::BHPKG::BAbstractBufferedDataReader; using BPackageKit::BHPKG::BAbstractBufferedDataReader;
using BPackageKit::BHPKG::BDataOutput;
using BPackageKit::BHPKG::BDataReader; using BPackageKit::BHPKG::BDataReader;
@@ -30,7 +29,7 @@ public:
virtual status_t ReadData(off_t offset, void* buffer, virtual status_t ReadData(off_t offset, void* buffer,
size_t size); size_t size);
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output); BDataIO* output);
private: private:
class CacheLineLocker class CacheLineLocker
@@ -121,7 +120,7 @@ private:
private: private:
status_t _ReadCacheLine(off_t lineOffset, status_t _ReadCacheLine(off_t lineOffset,
size_t lineSize, off_t requestOffset, size_t lineSize, off_t requestOffset,
size_t requestLength, BDataOutput* output); size_t requestLength, BDataIO* output);
void _DiscardPages(vm_page** pages, size_t firstPage, void _DiscardPages(vm_page** pages, size_t firstPage,
size_t pageCount); size_t pageCount);
@@ -129,7 +128,7 @@ private:
size_t pageCount); size_t pageCount);
status_t _WritePages(vm_page** pages, status_t _WritePages(vm_page** pages,
size_t pagesRelativeOffset, size_t pagesRelativeOffset,
size_t requestLength, BDataOutput* output); size_t requestLength, BDataIO* output);
status_t _ReadIntoPages(vm_page** pages, status_t _ReadIntoPages(vm_page** pages,
size_t firstPage, size_t pageCount); size_t firstPage, size_t pageCount);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2011, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -39,7 +39,6 @@
using namespace BPackageKit; using namespace BPackageKit;
using BPackageKit::BHPKG::BDataOutput;
using BPackageKit::BHPKG::BErrorOutput; using BPackageKit::BHPKG::BErrorOutput;
using BPackageKit::BHPKG::BFDDataReader; using BPackageKit::BHPKG::BFDDataReader;
using BPackageKit::BHPKG::BPackageInfoAttributeValue; using BPackageKit::BHPKG::BPackageInfoAttributeValue;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2013, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -11,13 +11,13 @@
#include <fs_cache.h> #include <fs_cache.h>
#include <AutoDeleter.h> #include <DataIO.h>
#include <util/AutoLock.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/DataReader.h> #include <package/hpkg/DataReader.h>
#include <package/hpkg/PackageDataReader.h> #include <package/hpkg/PackageDataReader.h>
#include <AutoDeleter.h>
#include <util/AutoLock.h>
#include "DebugSupport.h" #include "DebugSupport.h"
#include "GlobalFactory.h" #include "GlobalFactory.h"
#include "Package.h" #include "Package.h"
@@ -29,7 +29,7 @@ using namespace BPackageKit::BHPKG;
// #pragma mark - DataAccessor // #pragma mark - DataAccessor
struct PackageFile::IORequestOutput : BDataOutput { struct PackageFile::IORequestOutput : BDataIO {
public: public:
IORequestOutput(io_request* request) IORequestOutput(io_request* request)
: :
@@ -37,9 +37,10 @@ public:
{ {
} }
virtual status_t WriteData(const void* buffer, size_t size) virtual ssize_t Write(const void* buffer, size_t size)
{ {
RETURN_ERROR(write_to_io_request(fRequest, buffer, size)); status_t error = write_to_io_request(fRequest, buffer, size);
RETURN_ERROR(error == B_OK ? (ssize_t)size : (ssize_t)error);
} }
private: private:
-1
View File
@@ -35,7 +35,6 @@ HPKG_SOURCES =
BlockBufferPoolNoLock.cpp BlockBufferPoolNoLock.cpp
BufferPool.cpp BufferPool.cpp
PoolBuffer.cpp PoolBuffer.cpp
DataOutput.cpp
DataReader.cpp DataReader.cpp
DataWriters.cpp DataWriters.cpp
ErrorOutput.cpp ErrorOutput.cpp
-1
View File
@@ -15,7 +15,6 @@ HPKG_SOURCES =
BlockBufferPoolNoLock.cpp BlockBufferPoolNoLock.cpp
BufferPool.cpp BufferPool.cpp
CommitTransactionResult.cpp CommitTransactionResult.cpp
DataOutput.cpp
DataReader.cpp DataReader.cpp
DataWriters.cpp DataWriters.cpp
ErrorOutput.cpp ErrorOutput.cpp
-54
View File
@@ -1,54 +0,0 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/DataOutput.h>
#include <string.h>
namespace BPackageKit {
namespace BHPKG {
// #pragma mark - BDataOutput
BDataOutput::~BDataOutput()
{
}
// #pragma mark - BBufferDataOutput
BBufferDataOutput::BBufferDataOutput(void* buffer, size_t size)
:
fBuffer(buffer),
fSize(size),
fBytesWritten(0)
{
}
status_t
BBufferDataOutput::WriteData(const void* buffer, size_t size)
{
if (size == 0)
return B_OK;
if (size > fSize - fBytesWritten)
return B_BAD_VALUE;
memcpy((uint8*)fBuffer + fBytesWritten, buffer, size);
fBytesWritten += size;
return B_OK;
}
} // namespace BHPKG
} // namespace BPackageKit
+5 -6
View File
@@ -1,12 +1,12 @@
/* /*
* Copyright 2009-2011, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <package/hpkg/DataReader.h> #include <package/hpkg/DataReader.h>
#include <package/hpkg/DataOutput.h> #include <DataIO.h>
#include <string.h> #include <string.h>
@@ -35,7 +35,7 @@ BAbstractBufferedDataReader::~BAbstractBufferedDataReader()
status_t status_t
BAbstractBufferedDataReader::ReadData(off_t offset, void* buffer, size_t size) BAbstractBufferedDataReader::ReadData(off_t offset, void* buffer, size_t size)
{ {
BBufferDataOutput output(buffer, size); BMemoryIO output(buffer, size);
return ReadDataToOutput(offset, size, &output); return ReadDataToOutput(offset, size, &output);
} }
@@ -69,8 +69,7 @@ BBufferDataReader::ReadData(off_t offset, void* buffer, size_t size)
status_t status_t
BBufferDataReader::ReadDataToOutput(off_t offset, size_t size, BBufferDataReader::ReadDataToOutput(off_t offset, size_t size, BDataIO* output)
BDataOutput* output)
{ {
if (size == 0) if (size == 0)
return B_OK; return B_OK;
@@ -81,7 +80,7 @@ BBufferDataReader::ReadDataToOutput(off_t offset, size_t size,
if (size > fSize || offset > (off_t)fSize - (off_t)size) if (size > fSize || offset > (off_t)fSize - (off_t)size)
return B_ERROR; return B_ERROR;
return output->WriteData((const uint8*)fData + offset, size); return output->WriteExactly((const uint8*)fData + offset, size);
} }
+5 -4
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Copyright 2013, Ingo Weinhold, [email protected]. * Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -111,10 +111,11 @@ ZlibDataWriter::WriteDataNoThrow(const void* buffer,
} }
status_t ssize_t
ZlibDataWriter::WriteData(const void* buffer, size_t size) ZlibDataWriter::Write(const void* buffer, size_t size)
{ {
return fDataWriter->WriteDataNoThrow(buffer, size); status_t error = fDataWriter->WriteDataNoThrow(buffer, size);
return error == B_OK ? (ssize_t)size : (ssize_t)error;
} }
+3 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2013, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -53,7 +53,7 @@ public:
} }
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) BDataIO* output)
{ {
if (size == 0) if (size == 0)
return B_OK; return B_OK;
@@ -74,7 +74,7 @@ private:
}; };
// #pragma mark - PackageDataHeapReader // #pragma mark - PackageDataInlineReader
class PackageDataInlineReader : public BBufferDataReader { class PackageDataInlineReader : public BBufferDataReader {
@@ -1,5 +1,5 @@
/* /*
* Copyright 2013, Ingo Weinhold, [email protected]. * Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -14,7 +14,7 @@
#include <new> #include <new>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <package/hpkg/DataOutput.h> #include <DataIO.h>
#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/ErrorOutput.h>
#include <AutoDeleter.h> #include <AutoDeleter.h>
@@ -140,7 +140,7 @@ PackageFileHeapAccessorBase::~PackageFileHeapAccessorBase()
status_t status_t
PackageFileHeapAccessorBase::ReadDataToOutput(off_t offset, size_t size, PackageFileHeapAccessorBase::ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) BDataIO* output)
{ {
if (size == 0) if (size == 0)
return B_OK; return B_OK;
@@ -174,7 +174,7 @@ PackageFileHeapAccessorBase::ReadDataToOutput(off_t offset, size_t size,
// The last chunk may be shorter than kChunkSize, but since // The last chunk may be shorter than kChunkSize, but since
// size (and thus remainingSize) had been clamped, that doesn't // size (and thus remainingSize) had been clamped, that doesn't
// harm. // harm.
error = output->WriteData( error = output->WriteExactly(
(char*)uncompressedDataBuffer + inChunkOffset, toWrite); (char*)uncompressedDataBuffer + inChunkOffset, toWrite);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2013, Ingo Weinhold, [email protected]. * Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -461,7 +461,7 @@ PackageFileHeapWriter::ReadAndDecompressChunk(size_t chunkIndex,
// The chunk has not been written to disk yet. Its data are still in the // The chunk has not been written to disk yet. Its data are still in the
// pending data buffer. // pending data buffer.
memcpy(uncompressedDataBuffer, fPendingDataBuffer, fPendingDataSize); memcpy(uncompressedDataBuffer, fPendingDataBuffer, fPendingDataSize);
// TODO: This can be optimized. Since we write to a BDataOutput anyway, // TODO: This can be optimized. Since we write to a BDataIO anyway,
// there's no need to copy the data. // there's no need to copy the data.
return B_OK; return B_OK;
} }
@@ -22,7 +22,6 @@
#include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/HPKGDefsPrivate.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/PackageData.h> #include <package/hpkg/PackageData.h>
#include <package/hpkg/PackageEntry.h> #include <package/hpkg/PackageEntry.h>
#include <package/hpkg/PackageEntryAttribute.h> #include <package/hpkg/PackageEntryAttribute.h>
+1 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2013, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -37,7 +37,6 @@
#include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/HPKGDefsPrivate.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/DataReader.h> #include <package/hpkg/DataReader.h>
#include <package/hpkg/PackageFileHeapWriter.h> #include <package/hpkg/PackageFileHeapWriter.h>
#include <package/hpkg/PackageReaderImpl.h> #include <package/hpkg/PackageReaderImpl.h>
+3 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2011, Ingo Weinhold, [email protected]. * Copyright 2009-2014, Ingo Weinhold, [email protected].
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -16,10 +16,10 @@
#include <new> #include <new>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <DataIO.h>
#include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/HPKGDefsPrivate.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/PackageFileHeapReader.h> #include <package/hpkg/PackageFileHeapReader.h>
#include <package/hpkg/ZlibDecompressor.h> #include <package/hpkg/ZlibDecompressor.h>
@@ -1358,7 +1358,7 @@ ReaderImplBase::ReadBuffer(off_t offset, void* buffer, size_t size)
status_t status_t
ReaderImplBase::ReadSection(const PackageFileSection& section) ReaderImplBase::ReadSection(const PackageFileSection& section)
{ {
BBufferDataOutput output(section.data, section.uncompressedLength); BMemoryIO output(section.data, section.uncompressedLength);
return fHeapReader->ReadDataToOutput(section.offset, return fHeapReader->ReadDataToOutput(section.offset,
section.uncompressedLength, &output); section.uncompressedLength, &output);
} }
+5 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -9,7 +9,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <package/hpkg/DataOutput.h> #include <DataIO.h>
namespace BPackageKit { namespace BPackageKit {
@@ -22,7 +22,7 @@ namespace BPrivate {
static const size_t kOutputBufferSize = 1024; static const size_t kOutputBufferSize = 1024;
ZlibCompressor::ZlibCompressor(BDataOutput* output) ZlibCompressor::ZlibCompressor(BDataIO* output)
: :
fOutput(output), fOutput(output),
fStreamInitialized(false) fStreamInitialized(false)
@@ -82,7 +82,7 @@ ZlibCompressor::CompressNext(const void* input, size_t inputSize)
return TranslateZlibError(zlibError); return TranslateZlibError(zlibError);
if (fStream.avail_out < sizeof(outputBuffer)) { if (fStream.avail_out < sizeof(outputBuffer)) {
status_t error = fOutput->WriteData(outputBuffer, status_t error = fOutput->WriteExactly(outputBuffer,
sizeof(outputBuffer) - fStream.avail_out); sizeof(outputBuffer) - fStream.avail_out);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -109,7 +109,7 @@ ZlibCompressor::Finish()
return TranslateZlibError(zlibError); return TranslateZlibError(zlibError);
if (fStream.avail_out < sizeof(outputBuffer)) { if (fStream.avail_out < sizeof(outputBuffer)) {
status_t error = fOutput->WriteData(outputBuffer, status_t error = fOutput->WriteExactly(outputBuffer,
sizeof(outputBuffer) - fStream.avail_out); sizeof(outputBuffer) - fStream.avail_out);
if (error != B_OK) if (error != B_OK)
return error; return error;
+5 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -9,7 +9,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <package/hpkg/DataOutput.h> #include <DataIO.h>
namespace BPackageKit { namespace BPackageKit {
@@ -23,7 +23,7 @@ namespace BPrivate {
static const size_t kOutputBufferSize = 1024; static const size_t kOutputBufferSize = 1024;
ZlibDecompressor::ZlibDecompressor(BDataOutput* output) ZlibDecompressor::ZlibDecompressor(BDataIO* output)
: :
fOutput(output), fOutput(output),
fStreamInitialized(false), fStreamInitialized(false),
@@ -89,7 +89,7 @@ ZlibDecompressor::DecompressNext(const void* input, size_t inputSize)
return TranslateZlibError(zlibError); return TranslateZlibError(zlibError);
if (fStream.avail_out < sizeof(outputBuffer)) { if (fStream.avail_out < sizeof(outputBuffer)) {
status_t error = fOutput->WriteData(outputBuffer, status_t error = fOutput->WriteExactly(outputBuffer,
sizeof(outputBuffer) - fStream.avail_out); sizeof(outputBuffer) - fStream.avail_out);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -118,7 +118,7 @@ ZlibDecompressor::Finish()
return TranslateZlibError(zlibError); return TranslateZlibError(zlibError);
if (fStream.avail_out < sizeof(outputBuffer)) { if (fStream.avail_out < sizeof(outputBuffer)) {
status_t error = fOutput->WriteData(outputBuffer, status_t error = fOutput->WriteExactly(outputBuffer,
sizeof(outputBuffer) - fStream.avail_out); sizeof(outputBuffer) - fStream.avail_out);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -11,9 +11,9 @@
#include <algorithm> #include <algorithm>
#include <new> #include <new>
#include <DataIO.h>
#include <package/hpkg/BufferPool.h> #include <package/hpkg/BufferPool.h>
#include <package/hpkg/PoolBuffer.h> #include <package/hpkg/PoolBuffer.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/v1/HPKGDefsPrivate.h> #include <package/hpkg/v1/HPKGDefsPrivate.h>
#include <package/hpkg/v1/PackageData.h> #include <package/hpkg/v1/PackageData.h>
#include <package/hpkg/ZlibDecompressor.h> #include <package/hpkg/ZlibDecompressor.h>
@@ -98,7 +98,7 @@ public:
} }
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) BDataIO* output)
{ {
if (size == 0) if (size == 0)
return B_OK; return B_OK;
@@ -125,7 +125,7 @@ public:
return error; return error;
// write to the output // write to the output
error = output->WriteData(buffer->Buffer(), toRead); error = output->WriteExactly(buffer->Buffer(), toRead);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -205,7 +205,7 @@ public:
} }
virtual status_t ReadDataToOutput(off_t offset, size_t size, virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) BDataIO* output)
{ {
// check offset and size // check offset and size
if (size == 0) if (size == 0)
@@ -244,7 +244,7 @@ public:
// write data to output // write data to output
size_t toCopy = std::min(size, (size_t)fChunkSize - inChunkOffset); size_t toCopy = std::min(size, (size_t)fChunkSize - inChunkOffset);
error = output->WriteData( error = output->WriteExactly(
(uint8*)fUncompressBuffer->Buffer() + inChunkOffset, toCopy); (uint8*)fUncompressBuffer->Buffer() + inChunkOffset, toCopy);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -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> * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -22,7 +22,6 @@
#include <package/hpkg/v1/HPKGDefsPrivate.h> #include <package/hpkg/v1/HPKGDefsPrivate.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/ErrorOutput.h>
#include <package/hpkg/v1/PackageData.h> #include <package/hpkg/v1/PackageData.h>
#include <package/hpkg/v1/PackageEntry.h> #include <package/hpkg/v1/PackageEntry.h>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -16,10 +16,10 @@
#include <new> #include <new>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <DataIO.h>
#include <package/hpkg/v1/HPKGDefsPrivate.h> #include <package/hpkg/v1/HPKGDefsPrivate.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/ErrorOutput.h> #include <package/hpkg/ErrorOutput.h>
#include <package/hpkg/ZlibDecompressor.h> #include <package/hpkg/ZlibDecompressor.h>
@@ -1031,8 +1031,7 @@ ReaderImplBase::ReadCompressedBuffer(const SectionInfo& section)
case B_HPKG_COMPRESSION_ZLIB: case B_HPKG_COMPRESSION_ZLIB:
{ {
// init the decompressor // init the decompressor
BBufferDataOutput bufferOutput(section.data, BMemoryIO bufferOutput(section.data, section.uncompressedLength);
section.uncompressedLength);
ZlibDecompressor decompressor(&bufferOutput); ZlibDecompressor decompressor(&bufferOutput);
status_t error = decompressor.Init(); status_t error = decompressor.Init();
if (error != B_OK) if (error != B_OK)
@@ -1060,7 +1059,7 @@ ReaderImplBase::ReadCompressedBuffer(const SectionInfo& section)
return error; return error;
// verify that all data have been read // verify that all data have been read
if (bufferOutput.BytesWritten() != section.uncompressedLength) { if ((uint64)bufferOutput.Position() != section.uncompressedLength) {
fErrorOutput->PrintError("Error: Missing bytes in uncompressed " fErrorOutput->PrintError("Error: Missing bytes in uncompressed "
"buffer!\n"); "buffer!\n");
return B_BAD_DATA; return B_BAD_DATA;
+2 -1
View File
@@ -83,6 +83,7 @@ BootStaticLibrary boot_loader :
safemode_settings.cpp safemode_settings.cpp
StringHash.cpp StringHash.cpp
DataIO.cpp
Referenceable.cpp Referenceable.cpp
: -fno-pic : -fno-pic
@@ -135,7 +136,7 @@ SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ]
SEARCH on [ FGristFiles stage2_crt0.S ] SEARCH on [ FGristFiles stage2_crt0.S ]
= [ FDirName $(HAIKU_TOP) src system boot arch $(TARGET_KERNEL_ARCH) ] ; = [ FDirName $(HAIKU_TOP) src system boot arch $(TARGET_KERNEL_ARCH) ] ;
SEARCH on [ FGristFiles Referenceable.cpp ] SEARCH on [ FGristFiles DataIO.cpp Referenceable.cpp ]
= [ FDirName $(HAIKU_TOP) src kits support ] ; = [ FDirName $(HAIKU_TOP) src kits support ] ;
@@ -27,7 +27,6 @@ BootStaticLibrary boot_packagefs :
BlockBufferPoolNoLock.cpp BlockBufferPoolNoLock.cpp
BufferPool.cpp BufferPool.cpp
PoolBuffer.cpp PoolBuffer.cpp
DataOutput.cpp
DataReader.cpp DataReader.cpp
ErrorOutput.cpp ErrorOutput.cpp
FDDataReader.cpp FDDataReader.cpp
+1
View File
@@ -132,6 +132,7 @@ KernelMergeObject kernel_lib_posix.o :
SEARCH_SOURCE = [ FDirName $(HAIKU_TOP) src kits support ] ; SEARCH_SOURCE = [ FDirName $(HAIKU_TOP) src kits support ] ;
KernelMergeObject kernel_misc.o : KernelMergeObject kernel_misc.o :
DataIO.cpp
Referenceable.cpp Referenceable.cpp
: $(TARGET_KERNEL_PIC_CCFLAGS) : $(TARGET_KERNEL_PIC_CCFLAGS)