v1.1.0 - Added validation and line formatting, fixed zero-length padding. Added tests.

This commit is contained in:
2026-02-16 12:32:27 +00:00
parent 823cc324c4
commit db4f5e5ac2
5 changed files with 253 additions and 17 deletions
+11 -3
View File
@@ -6,7 +6,7 @@ Replaces the standard library's `base64.urlsafe_b64encode` and `base64.urlsafe_b
## Features
- **URL safe**: Uses only characters that are safe for URLs and filenames
- **Urlsafe**: Uses only characters that are safe for URLs and filenames
- **No padding**: Removes trailing `=` characters for cleaner output
- **String output**: Returns proper strings instead of bytes (unlike Python's standard library)
- **Fast**: Based on Python stdlib, with constant-time padding restoration
@@ -35,6 +35,14 @@ data = base64url.dec(text) # Recovers the bytes
Base64 encode bytes to a URL-safe string without padding.
### `dec(s: str) -> bytes`
### `dec(s: str, *, validate=True) -> bytes`
Decode URL-safe Base64 into bytes. Padding optional.
Decode URL-safe Base64 into bytes. Padding optional. Set `validate=False` to silently ignore any unknown characters (Python base64 default behavior).
### `enc_lines(data: bytes, length: int = 76) -> str`
Encode with newlines inserted every `length` characters.
### `dec_lines(s: str) -> bytes`
Decode formatted input, ignoring all whitespace (but not other unknown characters).