I am trying to provide a proper API for a read-only stream class. The std::istream interface is a little too complex since it contains formatting read, while I am only interested in binary read (have to deal with compressed streams).
I came up with (requires C99 <stdint.h>):
struct stream { virtual uintmax_t size() const = 0; virtual uintmax_t tell() const = 0; virtual bool read( char * out, size_t len ) = 0; virtual bool skip( uintmax_t len ) = 0; }; The question I find difficult to answer is whether or not size() should be part of the API. When data is read from a file on disk, I can simply use stat(2). When data is received via HTTP, I can simply read the value for Content-Length (RFC 2616)...
Is this safe to requires at library level this size() function ? Or this type of requirement should only be met at application level ?