Modules@robinpath/buffer
buffer

@robinpath/buffer

0.1.2Node.jsPublic

Buffer and encoding utilities: base64, base64url, hex, byte operations

Buffer

Buffer and encoding utilities: base64, base64url, hex, byte operations

Package: @robinpath/buffer | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the buffer module when you need to:

  • Create a base64 buffer from a string -- Use buffer.fromString to perform this operation
  • Convert a base64 buffer to string -- Use buffer.toString to perform this operation
  • Create base64 from hex string -- Use buffer.fromHex to perform this operation
  • Convert base64 to hex string -- Use buffer.toHex to perform this operation
  • Encode string to base64 -- Use buffer.toBase64 to perform this operation

Quick Reference

FunctionDescriptionReturns
fromStringCreate a base64 buffer from a stringBase64-encoded buffer
toStringConvert a base64 buffer to stringDecoded string
fromHexCreate base64 from hex stringBase64 string
toHexConvert base64 to hex stringHex string
toBase64Encode string to base64Base64 string
fromBase64Decode base64 to stringDecoded string
toBase64UrlEncode string to URL-safe base64Base64url string
fromBase64UrlDecode URL-safe base64 to stringDecoded string
byteLengthGet the byte length of a stringByte length
concatConcatenate multiple base64 buffersConcatenated base64 string
compareCompare two base64 buffers-1, 0, or 1
isBase64Check if a string is valid base64True if valid base64

Functions

fromString

Create a base64 buffer from a string

Module: buffer | Returns: string -- Base64-encoded buffer

buffer.fromString "hello"
ParameterTypeRequiredDescription
strstringYesInput string
encodingstringNoString encoding (default: utf-8)

toString

Convert a base64 buffer to string

Module: buffer | Returns: string -- Decoded string

buffer.toString "aGVsbG8="
ParameterTypeRequiredDescription
base64stringYesBase64 string
encodingstringNoOutput encoding (default: utf-8)

fromHex

Create base64 from hex string

Module: buffer | Returns: string -- Base64 string

buffer.fromHex "48656c6c6f"
ParameterTypeRequiredDescription
hexstringYesHex string

toHex

Convert base64 to hex string

Module: buffer | Returns: string -- Hex string

buffer.toHex "aGVsbG8="
ParameterTypeRequiredDescription
base64stringYesBase64 string

toBase64

Encode string to base64

Module: buffer | Returns: string -- Base64 string

buffer.toBase64 "hello"
ParameterTypeRequiredDescription
strstringYesInput string

fromBase64

Decode base64 to string

Module: buffer | Returns: string -- Decoded string

buffer.fromBase64 "aGVsbG8="
ParameterTypeRequiredDescription
base64stringYesBase64 string

toBase64Url

Encode string to URL-safe base64

Module: buffer | Returns: string -- Base64url string

buffer.toBase64Url "hello"
ParameterTypeRequiredDescription
strstringYesInput string

fromBase64Url

Decode URL-safe base64 to string

Module: buffer | Returns: string -- Decoded string

buffer.fromBase64Url "aGVsbG8"
ParameterTypeRequiredDescription
base64urlstringYesBase64url string

byteLength

Get the byte length of a string

Module: buffer | Returns: number -- Byte length

buffer.byteLength "hello"
ParameterTypeRequiredDescription
strstringYesInput string

concat

Concatenate multiple base64 buffers

Module: buffer | Returns: string -- Concatenated base64 string

buffer.concat "aGVs" "bG8="
ParameterTypeRequiredDescription
buffersstringYesBase64 strings to concatenate

compare

Compare two base64 buffers

Module: buffer | Returns: number -- -1, 0, or 1

buffer.compare "YQ==" "Yg=="
ParameterTypeRequiredDescription
astringYesFirst base64 string
bstringYesSecond base64 string

isBase64

Check if a string is valid base64

Module: buffer | Returns: boolean -- True if valid base64

buffer.isBase64 "aGVsbG8="
ParameterTypeRequiredDescription
strstringYesString to check

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "From string and validate result"
do
  set $result as buffer.fromString "hello"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Buffer workflow

Chain multiple buffer operations together.

@desc "From string, to string, and more"
do
  set $r_fromString as buffer.fromString "hello"
  set $r_toString as buffer.toString "aGVsbG8="
  set $r_fromHex as buffer.fromHex "48656c6c6f"
  print "All operations complete"
enddo

2. Safe fromString with validation

Check results before proceeding.

@desc "From string and validate result"
do
  set $result as buffer.fromString "hello"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/buffer

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size4.0 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities