2002-07-09 16:24:59 +04:00
|
|
|
//----------------------------------------------------------------------
|
2021-08-20 19:27:07 +03:00
|
|
|
// This software is part of the Haiku distribution and is covered
|
2017-02-10 06:03:59 +03:00
|
|
|
// by the MIT License.
|
2002-07-09 16:24:59 +04:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
/*!
|
|
|
|
\file OffsetFile.h
|
|
|
|
OffsetFile interface declaration.
|
|
|
|
*/
|
|
|
|
|
2002-08-12 11:24:02 +04:00
|
|
|
#ifndef _OFFSET_FILE_H
|
|
|
|
#define _OFFSET_FILE_H
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#include <DataIO.h>
|
|
|
|
#include <File.h>
|
|
|
|
|
2002-08-12 12:42:01 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
namespace Storage {
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\class OffsetFile
|
|
|
|
\brief Provides access to a file skipping a certain amount of bytes at
|
|
|
|
the beginning.
|
|
|
|
|
|
|
|
This class implements the BPositionIO interface to provide access to the
|
|
|
|
data of a file past a certain offset. This is very handy e.g. for dealing
|
|
|
|
with resources, as they always reside at the end of a file, but may start
|
|
|
|
at arbitrary offsets.
|
|
|
|
|
|
|
|
\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
|
|
|
|
|
|
|
|
\version 0.0.0
|
|
|
|
*/
|
|
|
|
class OffsetFile : public BPositionIO {
|
|
|
|
public:
|
|
|
|
OffsetFile();
|
|
|
|
OffsetFile(BFile *file, off_t offset);
|
|
|
|
virtual ~OffsetFile();
|
|
|
|
|
|
|
|
status_t SetTo(BFile *file, off_t offset);
|
|
|
|
void Unset();
|
|
|
|
status_t InitCheck() const;
|
|
|
|
|
|
|
|
BFile *File() const;
|
|
|
|
|
|
|
|
ssize_t ReadAt(off_t pos, void *buffer, size_t size);
|
|
|
|
ssize_t WriteAt(off_t pos, const void *buffer,
|
|
|
|
size_t size);
|
|
|
|
off_t Seek(off_t position, uint32 seekMode);
|
|
|
|
off_t Position() const;
|
|
|
|
|
|
|
|
status_t SetSize(off_t size);
|
2008-09-03 15:23:15 +04:00
|
|
|
status_t GetSize(off_t *size) const;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
off_t Offset() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BFile* fFile;
|
|
|
|
off_t fOffset;
|
|
|
|
off_t fCurrentPosition;
|
|
|
|
};
|
|
|
|
|
2002-08-12 12:42:01 +04:00
|
|
|
}; // namespace Storage
|
|
|
|
}; // namespace BPrivate
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-08-12 11:24:02 +04:00
|
|
|
#endif // _OFFSET_FILE_H
|
2002-08-12 12:42:01 +04:00
|
|
|
|
|
|
|
|