Development build 586e1bd4
Typst文档简体中文版v0.15.1 + dev 586e1bd4

bytes0.7.0起可用Go to source

A sequence of bytes.

This is conceptually similar to an array of integers between 0 and 255, but represented much more efficiently. You can iterate over it using a for loop.

You can convert

When reading data from a file, you can decide whether to load it as a string or as raw bytes.

#bytes((123, 160, 22, 0)) \ #bytes("Hello 😃") #let data = read( "rhino.png", encoding: none, ) // Magic bytes. #array(data.slice(0, 4)) \ #str(data.slice(1, 4))

构造函数
Question mark
0.7.0起可用Go to source

Converts a value to bytes.

Expand展开示例
#bytes("Hello 😃") \ #bytes((123, 160, 22, 0))
bytes(strbytesarray) → bytes

value
str or bytes or array
必需参数
Question mark
位置参数
Question mark

The value that should be converted to bytes.

定义
Question mark

len0.7.0起可用Go to source

The length in bytes.

self.len() → int

at0.7.0起可用Go to source

Returns the byte at the specified index. Returns the default value if the index is out of bounds or fails with an error if no default value was specified.

self.at(
int,default: any,
) → any

index
int
必需参数
Question mark
位置参数
Question mark

The index at which to retrieve the byte.

default
any

A default value to return if the index is out of bounds.

slice0.7.0起可用Go to source

Extracts a subslice of the bytes. Fails with an error if the start or end index is out of bounds.

self.slice() → bytes

start
int
必需参数
Question mark
位置参数
Question mark

The start index (inclusive).

end
none or int
位置参数
Question mark
默认值:none

The end index (exclusive). If omitted, the whole slice until the end is extracted.

count

The number of items to extract. This is equivalent to passing start + count as the end position. Mutually exclusive with end.