1 /* 2 * Copyright 2009,2011, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PACKAGE__HPKG__DATA_READER_H_ 6 #define _PACKAGE__HPKG__DATA_READER_H_ 7 8 9 #include <SupportDefs.h> 10 11 12 namespace BPackageKit { 13 14 namespace BHPKG { 15 16 17 class BDataOutput; 18 19 20 class BDataReader { 21 public: 22 virtual ~BDataReader(); 23 24 virtual status_t ReadData(off_t offset, void* buffer, 25 size_t size) = 0; 26 }; 27 28 29 class BAbstractBufferedDataReader : public BDataReader { 30 public: 31 virtual ~BAbstractBufferedDataReader(); 32 33 virtual status_t ReadData(off_t offset, void* buffer, 34 size_t size); 35 virtual status_t ReadDataToOutput(off_t offset, size_t size, 36 BDataOutput* output) = 0; 37 }; 38 39 40 class BFDDataReader : public BDataReader { 41 public: 42 BFDDataReader(int fd); 43 44 void SetFD(int fd); 45 46 virtual status_t ReadData(off_t offset, void* buffer, 47 size_t size); 48 49 private: 50 int fFD; 51 }; 52 53 54 class BAttributeDataReader : public BDataReader { 55 public: 56 BAttributeDataReader(int fd, 57 const char* attribute, uint32 type); 58 59 virtual status_t ReadData(off_t offset, void* buffer, 60 size_t size); 61 62 private: 63 int fFD; 64 uint32 fType; 65 const char* fAttribute; 66 }; 67 68 69 class BBufferDataReader : public BAbstractBufferedDataReader { 70 public: 71 BBufferDataReader(const void* data, size_t size); 72 73 virtual status_t ReadData(off_t offset, void* buffer, 74 size_t size); 75 virtual status_t ReadDataToOutput(off_t offset, size_t size, 76 BDataOutput* output); 77 78 private: 79 const void* fData; 80 size_t fSize; 81 }; 82 83 84 } // namespace BHPKG 85 86 } // namespace BPackageKit 87 88 89 #endif // _PACKAGE__HPKG__DATA_READER_H_ 90