-
Notifications
You must be signed in to change notification settings - Fork 77
Strings and Blobs
Zade Viggers edited this page May 23, 2024
·
4 revisions
Note
This page has been updated for jDataView 3
jDataView supports additional Char
, String
and Bytes
types.
String
operations all support 'binary'
(by default) and 'utf-8'
encodings.
Additionally, getString
supports all the encodings supported by TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding).
Char
is always encoded as one-byte 'binary'
.
The setter methods for Bytes
will accept any ArrayLike<number>
, but the getter method will always return a Uint8Array
of bytes.
See writeXXX methods to understand the write
variants of the set
methods.
// Read a string using the specified encoding, or binary if unspecified
view.getString(byteLength: number, byteOffset: number | undefined, encoding = 'binary'): string
// Set a string using the specified encoding, or binary if unspecified
view.setString(byteOffset: number | undefined, str: string, encoding = 'binary'): void
view.writeString(str: string, encoding = 'binary'): void
// Get a single character. This is the same as getting a 1-length string using binary encoding
view.getChar(byteOffset: number | undefined): string
// Set a single character. This is the same as setting a 1-length string using binary encoding
view.setChar(byteOffset: number | undefined, char: string): void
view.writeChar(char: string): void
// Get raw bytes. If length is undefined, it will go to the end of the buffer.
view.getBytes(length: number, byteOffset: number | undefined, littleEndian = true, toArray = false): Uint8Array
// Directly set raw bytes
view.setBytes(byteOffset: number | undefined, bytes: ArrayLike<number>, littleEndian = true): void
view.writeBytes(bytes: ArrayLike<number>, littleEndian = true): void