Skip to content

Commit d91b948

Browse files
authored
Enhance BinaryString with base32 encoding support
Added support for base32 encoding and decoding in BinaryString.
1 parent d83f0c2 commit d91b948

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

content/3.libraries/100.php/binary-tools.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ composer require kduma/binary-tools
3333

3434
- **Safe binary data manipulation** with bounds checking
3535
- **UTF-8 string validation** for text data
36-
- **Multiple encoding formats** (hex, base64)
36+
- **Multiple encoding formats** (hex, base64, base32)
3737
- **Secure string comparison** using `hash_equals()`
3838
- **Big-endian integer support** for network protocols
3939
- **Position tracking** for streaming operations
@@ -52,6 +52,7 @@ Stream-like writer for building binary data structures.
5252

5353
Stream-like reader for parsing binary data with position tracking.
5454

55+
5556
## Usage Examples
5657

5758
### BinaryString
@@ -64,13 +65,15 @@ $binary = BinaryString::fromString("\x48\x65\x6c\x6c\x6f");
6465
$fromString = BinaryString::fromString("Hello");
6566
$fromHex = BinaryString::fromHex("48656c6c6f");
6667
$fromBase64 = BinaryString::fromBase64("SGVsbG8=");
68+
$fromBase32 = BinaryString::fromBase32("JBSWY3DP");
6769

6870
// All represent "Hello"
6971
echo $binary->toString(); // "Hello"
7072

7173
// Convert to different formats
7274
echo $binary->toHex(); // "48656c6c6f"
7375
echo $binary->toBase64(); // "SGVsbG8="
76+
echo $binary->toBase32(); // "JBSWY3DP"
7477
echo $binary->size(); // 5
7578

7679
// Secure comparison
@@ -216,11 +219,13 @@ for ($i = 0; $i < $userCount; $i++) {
216219
| `toString(): string` | Get raw binary data |
217220
| `toHex(): string` | Convert to hexadecimal string |
218221
| `toBase64(): string` | Convert to base64 string |
222+
| `toBase32(string $alphabet = Base32::DEFAULT_ALPHABET): string` | Convert to base32 string |
219223
| `size(): int` | Get byte length |
220224
| `equals(BinaryString $other): bool` | Secure comparison |
221225
| `fromString(string $value): static` | Create from string |
222226
| `fromHex(string $hex): static` | Create from hex string |
223227
| `fromBase64(string $base64): static` | Create from base64 |
228+
| `fromBase32(string $base32, string $alphabet = Base32::DEFAULT_ALPHABET): static` | Create from base32 string |
224229

225230
### BinaryWriter
226231

@@ -257,11 +262,12 @@ for ($i = 0; $i < $userCount; $i++) {
257262
| `seek(int $position): void` | Seek to position |
258263
| `skip(int $count): void` | Skip N bytes |
259264

265+
260266
## Error Handling
261267

262268
The library throws appropriate exceptions for error conditions:
263269

264-
- `InvalidArgumentException` - Invalid parameters (e.g., byte values > 255)
270+
- `InvalidArgumentException` - Invalid parameters (e.g., byte values > 255, invalid Base32 alphabet, invalid Base32 characters)
265271
- `RuntimeException` - Runtime errors (e.g., reading past end of data, invalid UTF-8)
266272

267273
```php

0 commit comments

Comments
 (0)