DataReader.h revision 32832cbe
1/*
2 * Copyright 2009-2014, 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
12class BDataIO;
13
14
15namespace BPackageKit {
16
17namespace BHPKG {
18
19
20class BDataReader {
21public:
22	virtual						~BDataReader();
23
24	virtual	status_t			ReadData(off_t offset, void* buffer,
25									size_t size) = 0;
26};
27
28
29class BAbstractBufferedDataReader : public BDataReader {
30public:
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									BDataIO* output) = 0;
37};
38
39
40class BFDDataReader : public BDataReader {
41public:
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
49private:
50			int					fFD;
51};
52
53
54class BAttributeDataReader : public BDataReader {
55public:
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
62private:
63			int					fFD;
64			uint32				fType;
65			const char*			fAttribute;
66};
67
68
69class BBufferDataReader : public BAbstractBufferedDataReader {
70public:
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									BDataIO* output);
77
78private:
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