1//----------------------------------------------------------------------
2//  This software is part of the Haiku distribution and is covered
3//  by the MIT License.
4//---------------------------------------------------------------------
5/*!
6	\file OffsetFile.h
7	OffsetFile interface declaration.
8*/
9
10#ifndef _OFFSET_FILE_H
11#define _OFFSET_FILE_H
12
13#include <DataIO.h>
14#include <File.h>
15
16namespace BPrivate {
17namespace Storage {
18
19/*!
20	\class OffsetFile
21	\brief Provides access to a file skipping a certain amount of bytes at
22	the beginning.
23
24	This class implements the BPositionIO interface to provide access to the
25	data of a file past a certain offset. This is very handy e.g. for dealing
26	with resources, as they always reside at the end of a file, but may start
27	at arbitrary offsets.
28
29	\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
30
31	\version 0.0.0
32*/
33class OffsetFile : public BPositionIO {
34public:
35	OffsetFile();
36	OffsetFile(BFile *file, off_t offset);
37	virtual ~OffsetFile();
38
39	status_t SetTo(BFile *file, off_t offset);
40	void Unset();
41	status_t InitCheck() const;
42
43	BFile *File() const;
44
45	ssize_t ReadAt(off_t pos, void *buffer, size_t size);
46	ssize_t WriteAt(off_t pos, const void *buffer,
47								size_t size);
48	off_t Seek(off_t position, uint32 seekMode);
49	off_t Position() const;
50
51	status_t SetSize(off_t size);
52	status_t GetSize(off_t *size) const;
53
54	off_t Offset() const;
55
56private:
57	BFile*				fFile;
58	off_t				fOffset;
59	off_t				fCurrentPosition;
60};
61
62};	// namespace Storage
63};	// namespace BPrivate
64
65#endif	// _OFFSET_FILE_H
66
67
68