ByteView
Work with bytes. Can be used as a Buffer, TypedArray, BitView, DataView.
Client side and server side support. Encode strings & serialize objects.
Table of Contents
Install
npm i byteview
Usage
static ByteView.from:
import ByteView from 'byteview'
const bv = ByteView.from('Hello World!')
console.log(bv)
class ByteView extends Uint8Array {
static from (
input: ArrayLike | ArrayBufferView | ArrayBuffer | string | bigint,
encodingOrOffset?: string | number,
length?: number
): ByteView
static alloc (size: number, encoding?: string): ByteView
static allocBits (size: number, encoding?: string): ByteView
static concat (list: Array<ByteView>, length?: number): ByteView
static isByteView (byteView: any): boolean
static isView (input: any): boolean
static isNativeBuffer (input: any): boolean
static serialize (input: object): string
static byteLength (
string: string,
encoding = 'utf8'
): number
static isOSLittleEndian: boolean
get size (): number
get bitOffset (): number
get encoding (): string
set encoding (encoding: string)
swap16 (): this
swap32 (): this
swap64 (): this
getRGB (index: number): [number, number, number]
getColorHex (index: number): string
getBit (index: number): 1 | 0
setBit (index: number, value: number): number
sliceBits (start: number, end: number): number
getUint5 (index: number): number
getUint6 (index: number): number
getUint8 (offset: number): number
setUint8 (
offset: number,
value: number
): number
getUint16 (
offset: number,
littleEndian = ByteView.isOSLittleEndian
): number
setUint16 (
offset: number,
value: number,
littleEndian = ByteView.isOSLittleEndian
): number
getUint32 (
offset: number,
littleEndian = ByteView.isOSLittleEndian
): number
setUint32 (
offset: number,
value: number,
littleEndian = ByteView.isOSLittleEndian
): number
getBigUint64 (
offset: number,
littleEndian = ByteView.isOSLittleEndian
): bigint
setBigUint64 (
offset: number,
value: bigint,
littleEndian = ByteView.isOSLittleEndian
): number
getInt (
offset: number,
byteLength: number,
littleEndian = ByteView.isOSLittleEndian
): number
getInt8 (offset: number): number
setInt8 (offset: number, value: number): number
getInt16 (
offset: number,
littleEndian = ByteView.isOSLittleEndian
): number
setInt16 (
offset: number,
value: number,
littleEndian = ByteView.isOSLittleEndian
): number
getInt32 (
offset: number,
littleEndian = ByteView.isOSLittleEndian
): number
setInt32 (
offset: number,
value: number,
littleEndian = ByteView.isOSLittleEndian
): number
getInt6 (index: number): number
toJSON (): {
type: 'ByteView',
data: Array<number>
}
inspect (): string
toString (
encoding?: 'utf8' |
'hex' |
'base32' |
'base32hex' |
'base32crockford' |
'base64' |
'base64url' |
'ascii' |
'latin1' |
'binary' |
'ucs2' |
'ucs-2' |
'utf16le' |
'utf-16le'
): string
subarray (start: number, end?: number): ByteView
copy (
target: ByteView | ArrayBufferView,
targetStart?: number,
start?: number,
end?: number
): number
fill (
val: ByteView | number | Array,
start: number,
end?: number,
encoding?: number
): this
equals (byteView: ByteView): boolean
compare (
target: ByteView,
start?: number,
end?: number,
thisStart?: number,
thisEnd?: number
): -1 | 0 | 1
write (
string: string,
offset: number,
length?: number,
encoding?: string
): number
toBigInt (): bigint
padStart (targetLength: number): this
}