problem: what if the file is a stream like stdin?

then there's not really a way to do this.  hmf...

give up on pure streams and require a seeking interface?