xref: /haiku/headers/os/package/hpkg/DataReader.h (revision 323b65468e5836bb27a5e373b14027d902349437)
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 BDataReader {
18 public:
19 	virtual						~BDataReader();
20 
21 	virtual	status_t			ReadData(off_t offset, void* buffer,
22 									size_t size) = 0;
23 };
24 
25 
26 class BFDDataReader : public BDataReader {
27 public:
28 								BFDDataReader(int fd);
29 
30 	virtual	status_t			ReadData(off_t offset, void* buffer,
31 									size_t size);
32 
33 private:
34 			int					fFD;
35 };
36 
37 
38 class BAttributeDataReader : public BDataReader {
39 public:
40 								BAttributeDataReader(int fd,
41 									const char* attribute, uint32 type);
42 
43 	virtual	status_t			ReadData(off_t offset, void* buffer,
44 									size_t size);
45 
46 private:
47 			int					fFD;
48 			uint32				fType;
49 			const char*			fAttribute;
50 };
51 
52 
53 class BBufferDataReader : public BDataReader {
54 public:
55 								BBufferDataReader(const void* data, size_t size);
56 
57 	virtual	status_t			ReadData(off_t offset, void* buffer,
58 									size_t size);
59 
60 private:
61 			const void*			fData;
62 			size_t				fSize;
63 };
64 
65 
66 }	// namespace BHPKG
67 
68 }	// namespace BPackageKit
69 
70 
71 #endif	// _PACKAGE__HPKG__DATA_READER_H_
72