deno.buffer
一个具有 read()
和 write()
方法大小可变的字节缓冲区。
A variable-sized buffer of bytes with read()
and write()
methods.
基于 Go Buffer。
Based on Go Buffer.
继承关系
- Buffer
实现了
索引
Constructors
Properties
Methods
Constructors
constructor
Properties
capacity
capacity: number
缓冲区底层字节片段的只读容量,即为缓冲区数据分配的总空间。
The read only capacity of the buffer’s underlying byte slice, that is, the total space allocated for the buffer’s data.
length
length: number
只读缓冲区未读部分的字节数。
A read only number of bytes of the unread portion of the buffer.
Methods
bytes
-
bytes(): Uint8Array
-
返回一个缓冲区未读部分的片段。
Returns a slice holding the unread portion of the buffer.
该片段只在下一次缓冲区修改之前有效 (即, 只有在下一次调用像
read()
,write()
,reset()
, 或者truncate()
这样的方法)。 该片段会在下一次修改缓冲区内容之前将缓冲区内容进行别名处理 , 所以立刻改变片段会影响未来读取的结果。The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like
read()
,write()
,reset()
, ortruncate()
). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads.返回 Uint8Array
empty
-
empty(): boolean
-
返回缓冲区的未读部分是否为空。
Returns whether the unread portion of the buffer is empty.
返回 boolean
grow
-
grow(n: number): void
-
增加缓冲区的容量,必要时保证另一个
n
字节的空间。 在.grow(n)
之后,至少可以将n
个字节写到缓冲区中而不需要另外分配。 若n
为负数,.grow()
将抛出异常。 当缓冲区不能增加的时候会抛出错误。Grows the buffer’s capacity, if necessary, to guarantee space for another
n
bytes. After.grow(n)
, at leastn
bytes can be written to the buffer without another allocation. Ifn
is negative,.grow()
will throw. If the buffer can’t grow it will throw an error.基于 Go Lang 的 Buffer.Grow。
Based on Go Lang’s Buffer.Grow.
参数
-
n: number
返回 void
-
read
-
read(p: Uint8Array): Promise<number | unique symbol>
-
在缓冲区中读取下一个
p.length
字节,或直到缓冲区用完为止。 解析读取的字节数。当缓冲区没有数据返回,则解析为Deno.EOF
。Reads the next
p.length
bytes from the buffer or until the buffer is drained. Resolves to the number of bytes read. If the buffer has no data to return, resolves toDeno.EOF
.参数
-
p: Uint8Array
返回 Promise<number | unique symbol>
-
readFrom
-
readFrom(r: Reader): Promise<number>
-
从
r
读取数据直到Deno.EOF
,并将其附加到缓冲区,根据需要扩展缓冲区。 解析读取的字节数。 如果缓冲区过大,.readFrom()
将会 reject 一个错误。Reads data from
r
untilDeno.EOF
and appends it to the buffer, growing the buffer as needed. It resolves to the number of bytes read. If the buffer becomes too large,.readFrom()
will reject with an error.基于 Go Lang 的 Buffer.ReadFrom。
Based on Go Lang’s Buffer.ReadFrom.
参数
-
r: Reader
返回 Promise<number>
-
readFromSync
-
readFromSync(r: SyncReader): number
-
从
r
读取数据直到Deno.EOF
,并将其附加到缓冲区,根据需要扩展缓冲区。 返回读取的字节数,如果缓冲区过大,.readFromSync()
将会抛出错误。Reads data from
r
untilDeno.EOF
and appends it to the buffer, growing the buffer as needed. It returns the number of bytes read. If the buffer becomes too large,.readFromSync()
will throw an error.基于 Go Lang 的 Buffer.ReadFrom。
Based on Go Lang’s Buffer.ReadFrom.
参数
-
r: SyncReader
返回 number
-
readSync
-
readSync(p: Uint8Array): number | unique symbol
-
实现了 SyncReader.readSync
在缓冲区中读取下一个
p.length
字节,或直到缓冲区用完为止。 返回只读的字节数。当缓冲区没有数据返回,则返回值为Deno.EOF
。Reads the next
p.length
bytes from the buffer or until the buffer is drained. Returns the number of bytes read. If the buffer has no data to return, the return isDeno.EOF
.参数
-
p: Uint8Array
返回 number | unique symbol
-
reset
-
reset(): void
-
将缓冲区重置为空,但它保留了底层存储供未来写入时使用,
.reset()
与.truncate(0)
相同。Resets the buffer to be empty, but it retains the underlying storage for use by future writes.
.reset()
is the same as.truncate(0)
.返回 void
toString
-
toString(): string
-
将缓冲区中未读部分的内容以
string
的形式返回。Returns the contents of the unread portion of the buffer as a
string
.警告: 当数据流经缓冲区时存在多个字节, 这种方法可能会因为字符被拆分而导致字符串的结果错误。
Warning: if multibyte characters are present when data is flowing through the buffer, this method may result in incorrect strings due to a character being split.
返回 string
truncate
-
truncate(n: number): void
-
除了缓冲器中开头
n
个未读字节之外,其他的所有字节都丢弃,但是继续使用相同分配的存储空间。 当n
为负数或者大于缓冲区的长度, 则会抛出异常。Discards all but the first
n
unread bytes from the buffer but continues to use the same allocated storage. It throws ifn
is negative or greater than the length of the buffer.参数
-
n: number
返回 void
-
write
-
write(p: Uint8Array): Promise<number>
-
参数
-
p: Uint8Array
返回 Promise<number>
-
writeSync
-
writeSync(p: Uint8Array): number
-
实现了 SyncWriter.writeSync
参数
-
p: Uint8Array
返回 number
-
图例说明
- Constructor
- Property
- Method
本文档使用 TypeDoc 生成。