Index: src/OFFile.m
==================================================================
--- src/OFFile.m
+++ src/OFFile.m
@@ -715,42 +715,17 @@
stream: self
requestedLength: length];
}
- (void)lowlevelSeekToOffset: (off_t)offset
-{
- if (lseek(fd, offset, SEEK_SET) == -1)
- @throw [OFSeekFailedException exceptionWithClass: [self class]
- stream: self
- offset: offset
- whence: SEEK_SET];
-}
-
-- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset
-{
- off_t ret;
-
- if ((ret = lseek(fd, offset, SEEK_CUR)) == -1)
- @throw [OFSeekFailedException exceptionWithClass: [self class]
- stream: self
- offset: offset
- whence: SEEK_CUR];
-
- return ret;
-}
-
-- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset
-{
- off_t ret;
-
- if ((ret = lseek(fd, offset, SEEK_END)) == -1)
- @throw [OFSeekFailedException exceptionWithClass: [self class]
- stream: self
- offset: offset
- whence: SEEK_END];
-
- return ret;
+ whence: (int)whence
+{
+ if (lseek(fd, offset, whence) == -1)
+ @throw [OFSeekFailedException exceptionWithClass: [self class]
+ stream: self
+ offset: offset
+ whence: whence];
}
- (int)fileDescriptorForReading
{
return fd;
@@ -820,22 +795,11 @@
selector: _cmd];
[super dealloc]; /* Get rid of stupid warning */
}
- (void)lowlevelSeekToOffset: (off_t)offset
-{
- @throw [OFNotImplementedException exceptionWithClass: [self class]
- selector: _cmd];
-}
-
-- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset
-{
- @throw [OFNotImplementedException exceptionWithClass: [self class]
- selector: _cmd];
-}
-
-- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset
+ whence: (int)whence
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
@end
Index: src/OFSeekableStream.h
==================================================================
--- src/OFSeekableStream.h
+++ src/OFSeekableStream.h
@@ -26,41 +26,28 @@
#import "OFStream.h"
/*!
* @brief A stream that supports seeking.
*
- * @note If you want to subclass this, override lowlevelSeekToOffset:,
- * lowlevelSeekForwardWithOffset: and lowlevelSeekToOffsetRelativeToEnd:,
- * but nothing else, as they do the actual work. OFSeekableStream uses
- * those and makes them work together with the caching of OFStream.
- * If you override these methods without the lowlevel prefix, you
- * will break caching, get broken results and seek to the wrong
- * position!
+ * @note If you want to subclass this, override
+ * @ref lowlevelSeekToOffset:whence:. OFSeekableStream uses this method
+ * and makes it work together with the caching of OFStream. If you
+ * override this methods without the lowlevel prefix, you will
+ * break caching, get broken results and seek to the wrong position!
*/
@interface OFSeekableStream: OFStream
/*!
* @brief Seeks to the specified absolute offset.
*
* @param offset The offset in bytes
- */
-- (void)seekToOffset: (off_t)offset;
-
-/*!
- * @brief Seeks to the specified offset, relative to the current location.
- *
- * @param offset The offset relative to the current location
- * @return The absolute offset
- */
-- (off_t)seekForwardWithOffset: (off_t)offset;
-
-/*!
- * @brief Seeks to the specified offset, relative to the end of the stream.
- *
- * @param offset The offset relative to the end of the stream
- * @return The absolute offset
- */
-- (off_t)seekToOffsetRelativeToEnd: (off_t)offset;
+ * @param whence From where to seek. Possible values are:
+ * * SEEK_SET: Seek to the specified byte.
+ * * SEEK_CUR: Seek to the current location + offset.
+ * * SEEK_END: Seek to the end of the stream + offset.
+ */
+- (void)seekToOffset: (off_t)offset
+ whence: (int)whence;
/*!
* @brief Seek the stream on the lowlevel.
*
* @warning Do not call this directly!
@@ -67,32 +54,13 @@
*
* Override this with this method with your actual seek implementation when
* subclassing!
*
* @param offset The offset to seek to
- */
-- (void)lowlevelSeekToOffset: (off_t)offset;
-
-/*!
- * @brief Seek the stream on the lowlevel.
- *
- * @warning Do not call this directly!
- *
- * Override this with this method with your actual seek implementation when
- * subclassing!
- *
- * @param offset The offset to seek forward to
- */
-- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset;
-
-/*!
- * @brief Seek the stream on the lowlevel.
- *
- * @warning Do not call this directly!
- *
- * Override this with this method with your actual seek implementation when
- * subclassing!
- *
- * @param offset The offset to seek to, relative to the end
- */
-- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset;
+ * @param whence From where to seek. Possible values are:
+ * * SEEK_SET: Seek to the specified byte.
+ * * SEEK_CUR: Seek to the current location + offset.
+ * * SEEK_END: Seek to the end of the stream + offset.
+ */
+- (void)lowlevelSeekToOffset: (off_t)offset
+ whence: (int)whence;
@end
Index: src/OFSeekableStream.m
==================================================================
--- src/OFSeekableStream.m
+++ src/OFSeekableStream.m
@@ -18,57 +18,22 @@
#import "OFNotImplementedException.h"
@implementation OFSeekableStream
- (void)lowlevelSeekToOffset: (off_t)offset
-{
- @throw [OFNotImplementedException exceptionWithClass: [self class]
- selector: _cmd];
-}
-
-- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset
-{
- @throw [OFNotImplementedException exceptionWithClass: [self class]
- selector: _cmd];
-}
-
-- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset
+ whence: (int)whence
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)seekToOffset: (off_t)offset
-{
- [self lowlevelSeekToOffset: offset];
-
- [self freeMemory: cache];
- cache = NULL;
- cacheLength = 0;
-}
-
-- (off_t)seekForwardWithOffset: (off_t)offset
-{
- off_t ret;
-
- ret = [self lowlevelSeekForwardWithOffset: offset - cacheLength];
-
- [self freeMemory: cache];
- cache = NULL;
- cacheLength = 0;
-
- return ret;
-}
-
-- (off_t)seekToOffsetRelativeToEnd: (off_t)offset
-{
- off_t ret;
-
- ret = [self lowlevelSeekToOffsetRelativeToEnd: offset];
-
- [self freeMemory: cache];
- cache = NULL;
- cacheLength = 0;
-
- return ret;
+ whence: (int)whence
+{
+ [self lowlevelSeekToOffset: offset
+ whence: whence];
+
+ [self freeMemory: cache];
+ cache = NULL;
+ cacheLength = 0;
}
@end