为什么`io.BytesIO`不是`io.BufferedRandom`实现?

时间:2015-05-26 09:17:23

标签: python python-3.x

这是一个有意的设计决策还是更像是设计监督,因为BytesIO可以提供这个(有用的)功能,而不需要任何开销。

所以我的问题是这个设计是否有特定的理由。

1 个答案:

答案 0 :(得分:-2)

我从文档中得知的是:

io.BytesIO继承BufferedIOBase

还提供了另外一种方法

getbuffer()
Return a readable and writable view over the contents of the buffer without copying them. Also, mutating the view will transparently update the contents of the buffer:

io.BufferedRandom()继承BufferedReader / Writer,后者继承BuffereIOBase

所以总体上它提供了四种额外的方法。

来自BufferedReader / Writer的

2:

peek([n])
Return bytes from the stream without advancing the position. At most one single read on the raw stream is done to satisfy the call. The number of bytes returned may be less or more than requested.

read([n])
Read and return n bytes, or if n is not given or negative, until EOF or if the read call would block in non-blocking mode.

2另外实施

 seek() 
 tell()