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(), or truncate()). 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 least n bytes can be written to the buffer without another allocation. If n 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>

  • 实现了 Reader.read

    在缓冲区中读取下一个 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 to Deno.EOF.

    参数

    • p: Uint8Array

    返回 Promise<number | unique symbol>

readFrom

  • readFrom(r: Reader): Promise<number>

  • r 读取数据直到 Deno.EOF,并将其附加到缓冲区,根据需要扩展缓冲区。 解析读取的字节数。 如果缓冲区过大,.readFrom() 将会 reject 一个错误。

    Reads data from r until Deno.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.

    参数

    返回 Promise<number>

readFromSync

  • readFromSync(r: SyncReader): number

  • r 读取数据直到 Deno.EOF,并将其附加到缓冲区,根据需要扩展缓冲区。 返回读取的字节数,如果缓冲区过大,.readFromSync() 将会抛出错误。

    Reads data from r until Deno.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.

    参数

    返回 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 is Deno.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 if n is negative or greater than the length of the buffer.

    参数

    • n: number

    返回 void

write

writeSync

图例说明

  • Constructor
  • Property
  • Method

本文档使用 TypeDoc 生成。

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了