@robinpath/buffer
0.1.2Node.jsPublicBuffer 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.fromStringto perform this operation - Convert a base64 buffer to string -- Use
buffer.toStringto perform this operation - Create base64 from hex string -- Use
buffer.fromHexto perform this operation - Convert base64 to hex string -- Use
buffer.toHexto perform this operation - Encode string to base64 -- Use
buffer.toBase64to perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
fromString | Create a base64 buffer from a string | Base64-encoded buffer |
toString | Convert a base64 buffer to string | Decoded string |
fromHex | Create base64 from hex string | Base64 string |
toHex | Convert base64 to hex string | Hex string |
toBase64 | Encode string to base64 | Base64 string |
fromBase64 | Decode base64 to string | Decoded string |
toBase64Url | Encode string to URL-safe base64 | Base64url string |
fromBase64Url | Decode URL-safe base64 to string | Decoded string |
byteLength | Get the byte length of a string | Byte length |
concat | Concatenate multiple base64 buffers | Concatenated base64 string |
compare | Compare two base64 buffers | -1, 0, or 1 |
isBase64 | Check if a string is valid base64 | True if valid base64 |
Functions
fromString
Create a base64 buffer from a string
Module: buffer | Returns: string -- Base64-encoded buffer
buffer.fromString "hello"
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | Input string |
encoding | string | No | String encoding (default: utf-8) |
toString
Convert a base64 buffer to string
Module: buffer | Returns: string -- Decoded string
buffer.toString "aGVsbG8="
| Parameter | Type | Required | Description |
|---|---|---|---|
base64 | string | Yes | Base64 string |
encoding | string | No | Output encoding (default: utf-8) |
fromHex
Create base64 from hex string
Module: buffer | Returns: string -- Base64 string
buffer.fromHex "48656c6c6f"
| Parameter | Type | Required | Description |
|---|---|---|---|
hex | string | Yes | Hex string |
toHex
Convert base64 to hex string
Module: buffer | Returns: string -- Hex string
buffer.toHex "aGVsbG8="
| Parameter | Type | Required | Description |
|---|---|---|---|
base64 | string | Yes | Base64 string |
toBase64
Encode string to base64
Module: buffer | Returns: string -- Base64 string
buffer.toBase64 "hello"
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | Input string |
fromBase64
Decode base64 to string
Module: buffer | Returns: string -- Decoded string
buffer.fromBase64 "aGVsbG8="
| Parameter | Type | Required | Description |
|---|---|---|---|
base64 | string | Yes | Base64 string |
toBase64Url
Encode string to URL-safe base64
Module: buffer | Returns: string -- Base64url string
buffer.toBase64Url "hello"
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | Input string |
fromBase64Url
Decode URL-safe base64 to string
Module: buffer | Returns: string -- Decoded string
buffer.fromBase64Url "aGVsbG8"
| Parameter | Type | Required | Description |
|---|---|---|---|
base64url | string | Yes | Base64url string |
byteLength
Get the byte length of a string
Module: buffer | Returns: number -- Byte length
buffer.byteLength "hello"
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | Input string |
concat
Concatenate multiple base64 buffers
Module: buffer | Returns: string -- Concatenated base64 string
buffer.concat "aGVs" "bG8="
| Parameter | Type | Required | Description |
|---|---|---|---|
buffers | string | Yes | Base64 strings to concatenate |
compare
Compare two base64 buffers
Module: buffer | Returns: number -- -1, 0, or 1
buffer.compare "YQ==" "Yg=="
| Parameter | Type | Required | Description |
|---|---|---|---|
a | string | Yes | First base64 string |
b | string | Yes | Second base64 string |
isBase64
Check if a string is valid base64
Module: buffer | Returns: boolean -- True if valid base64
buffer.isBase64 "aGVsbG8="
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | String to check |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
| (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)
| Version | Tag | Published |
|---|---|---|
| 0.1.2 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/buffer
