#mizchi/js_node/buffer

    #node:buffer

    Buffer type for binary data manipulation

    #Installation

    Add to your moon.pkg.json:

    { "import": [ "mizchi/js", "mizchi/js_node/buffer" ] }

    #Buffer Creation

    #Static Methods

    #Instance Methods

    #Read Methods

    #Write Methods

    #Iteration

    #External Types

    Buffer

    #external
    pub type Buffer

    Buffer::alloc

    fn Buffer::alloc(size : Int, fill? :
    Any
    , encoding? : String) -> Buffer

    Allocate a new zero-filled buffer

    Buffer::allocUnsafe

    #alias(alloc_unsafe)
    fn Buffer::allocUnsafe(size : Int) -> Buffer

    Allocate an uninitialized buffer (faster but potentially insecure)

    Buffer::as_any

    fn Buffer::as_any(self : Buffer) ->
    Any

    Buffer::buffer

    Get the underlying ArrayBuffer

    Buffer::byteLength

    #alias(byte_length)
    fn Buffer::byteLength(str : String, encoding? : String) -> Int

    Get the byte length of a string when encoded

    Buffer::byteOffset

    #alias(byte_offset)
    fn Buffer::byteOffset(self : Buffer) -> Int

    Get the byte offset in the underlying ArrayBuffer

    Buffer::compare

    fn Buffer::compare(buf1 : Buffer, buf2 : Buffer) -> Int

    Compare two buffers

    Buffer::compare_with

    fn Buffer::compare_with(self : Buffer, target : Buffer, target_start? : Int, target_end? : Int, source_start? : Int, source_end? : Int) -> Int

    Compare this buffer with another buffer

    Buffer::concat

    fn Buffer::concat(list : Array[Buffer], total_length? : Int) -> Buffer

    Concatenate an array of buffers

    Buffer::copy

    fn Buffer::copy(self : Buffer, target : Buffer, target_start? : Int, source_start? : Int, source_end? : Int) -> Int

    Copy data from this buffer to a target buffer

    Buffer::equals

    fn Buffer::equals(self : Buffer, other : Buffer) -> Bool

    Test if this buffer equals another buffer

    Buffer::fill

    fn Buffer::fill(self : Buffer, value :
    Any
    , offset? : Int, end? : Int, encoding? : String) -> Buffer

    Fill the buffer with a value

    Buffer::from_array

    fn Buffer::from_array(arr : Array[Int]) -> Buffer

    Create a Buffer from an array of bytes

    Buffer::from_arraybuffer

    fn Buffer::from_arraybuffer(ab :
    ArrayBuffer
    , byte_offset? : Int, length? : Int) -> Buffer

    Create a Buffer from an ArrayBuffer

    Buffer::from_buffer

    fn Buffer::from_buffer(buf : Buffer) -> Buffer

    Create a Buffer by copying another buffer

    Buffer::from_string

    fn Buffer::from_string(str : String, encoding? : String) -> Buffer

    Create a Buffer from a string with optional encoding

    Buffer::includes

    fn Buffer::includes(self : Buffer, value :
    Any
    , byte_offset? : Int, encoding? : String) -> Bool

    Check if the buffer includes a value

    Buffer::indexOf

    #alias(index_of)
    fn Buffer::indexOf(self : Buffer, value :
    Any
    , byte_offset? : Int, encoding? : String) -> Int

    Find the index of a value in the buffer

    Buffer::isBuffer

    #alias(is_buffer)
    fn Buffer::isBuffer(obj :
    Any
    ) -> Bool

    Check if an object is a Buffer

    Buffer::isEncoding

    #alias(is_encoding)
    fn Buffer::isEncoding(encoding : String) -> Bool

    Check if a string is a valid encoding

    Buffer::lastIndexOf

    #alias(last_index_of)
    fn Buffer::lastIndexOf(self : Buffer, value :
    Any
    , byte_offset? : Int, encoding? : String) -> Int

    Find the last index of a value in the buffer

    Buffer::length

    fn Buffer::length(self : Buffer) -> Int

    Get the length of the buffer in bytes

    Buffer::slice

    fn Buffer::slice(self : Buffer, start? : Int, end? : Int) -> Buffer

    Create a view of a portion of the buffer

    Buffer::subarray

    fn Buffer::subarray(self : Buffer, start? : Int, end? : Int) -> Buffer

    Create a subarray (TypedArray-compatible view)

    Buffer::toJSON

    #alias(to_json)
    fn Buffer::toJSON(self : Buffer) -> BufferJSON

    Convert buffer to JSON representation

    Buffer::toString

    #alias(to_string)
    fn Buffer::toString(self : Buffer, encoding? : String, start? : Int, end? : Int) -> String

    Convert buffer to string with optional encoding and range

    Buffer::write

    fn Buffer::write(self : Buffer, str : String, offset? : Int, length? : Int, encoding? : String) -> Int

    Write a string to the buffer

    BufferJSON

    #external
    pub type BufferJSON

    BufferJSON - Result of Buffer.toJSON() Contains the type string "Buffer" and the data as an array of bytes

    BufferJSON::as_any

    BufferJSON::data

    fn BufferJSON::data(self : BufferJSON) -> Array[Int]

    Get the data as an array of bytes

    BufferJSON::type_

    fn BufferJSON::type_(self : BufferJSON) -> String

    Get the type field (always "Buffer")

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    ยฉ 2026 mooncakes.io