このページはまだ翻訳されていません。原文の内容が表示されています。
bytes
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
- a string or an array of integers to bytes with the
bytesconstructor - bytes to a string with the
strconstructor, with UTF-8 encoding - bytes to an array of integers with the
arrayconstructor
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))

コンストラクタ引数引数は関数への入力値です。関数名の後に括弧で囲んで指定します。
Converts a value to bytes.
- Strings are encoded in UTF-8.
- Arrays of integers between
0and255are converted directly. The dedicated byte representation is much more efficient than the array representation and thus typically used for large byte buffers (e.g. image data).
#bytes("Hello 😃") \
#bytes((123, 160, 22, 0))

bytes()->定義定義これらの関数や型には、関連する定義を持たせることができます。定義にアクセスするには、対象の関数や型の名前を指定した後に、ピリオド区切りで定義名を記述します。
at
atReturns 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(,any)->anyindex
indexThe index at which to retrieve the byte.
defaultany
defaultA default value to return if the index is out of bounds.
slice
sliceExtracts a subslice of the bytes. Fails with an error if the start or end index is out of bounds.
self.slice(,,)->start
startThe start index (inclusive).
The end index (exclusive). If omitted, the whole slice until the end is extracted.
デフォルト値:none
count
countThe number of items to extract. This is equivalent to passing
start + count as the end position. Mutually exclusive with
end.