--- /dev/null
+#ifndef MSP_IO_SLICE_H_
+#define MSP_IO_SLICE_H_
+
+#include "seekable.h"
+
+namespace Msp {
+namespace IO {
+
+/**
+Presents a part of seekable I/O object as if it was a complete object. This
+allows in-place access to embedded resources where the loader expects to
+receive a complete file.
+
+When a Slice is created, its read/write offset is placed at the beginning of
+its range. If the offset of the underlying object is changed, the Slice will
+restore it before the next access. This enables multiple Slices to be created
+on top of the same object.
+*/
+class Slice: public Seekable
+{
+private:
+ Seekable &below;
+ SeekOffset start_offset;
+ SeekOffset length;
+ SeekOffset position;
+ bool sync_position;
+
+public:
+ Slice(Seekable &, SeekOffset, SeekOffset);
+
+private:
+ void flush();
+
+ unsigned prepare_op(unsigned, Mode);
+protected:
+ virtual unsigned do_write(const char *, unsigned);
+ virtual unsigned do_read(char *, unsigned);
+
+public:
+ virtual unsigned put(char);
+ virtual int get();
+
+ virtual SeekOffset seek(SeekOffset, SeekType);
+ virtual SeekOffset tell() const { return position; }
+};
+
+} // namespace IO
+} // namespace Msp
+
+#endif