home / skills / aidotnet / moyucode / base64-encoder

base64-encoder skill

/skills/tools/base64-encoder

This skill encodes and decodes Base64, URL-safe Base64, and hexadecimal data, with file support for seamless binary-text conversions.

npx playbooks add skill aidotnet/moyucode --skill base64-encoder

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
931 B
---
name: base64-encoder
description: 编码和解码Base64、URL安全Base64和十六进制字符串,支持文件处理。
metadata:
  short-description: Base64编码/解码
source:
  repository: https://github.com/python/cpython
  license: PSF
---

# Base64 Encoder Tool

## Description
Encode and decode Base64, URL-safe Base64, and hexadecimal strings with support for files.

## Trigger
- `/base64` command
- User needs to encode/decode data
- User wants to convert binary to text

## Usage

```bash
# Encode text
python scripts/base64_encoder.py encode "Hello World"

# Decode Base64
python scripts/base64_encoder.py decode "SGVsbG8gV29ybGQ="

# Encode file
python scripts/base64_encoder.py encode --file image.png --output image.b64

# URL-safe encoding
python scripts/base64_encoder.py encode "data" --url-safe
```

## Tags
`base64`, `encode`, `decode`, `binary`, `text`

## Compatibility
- Codex: ✅
- Claude Code: ✅

Overview

This skill provides fast, reliable encoding and decoding for Base64, URL-safe Base64, and hexadecimal strings, with optional file input and output. It is implemented in TypeScript and designed for command-line use to convert between binary and text safely and predictably. The tool handles both raw strings and file streams, preserving data integrity across encodings.

How this skill works

The skill accepts text or file input and performs one of three transformations: Base64 encode/decode, URL-safe Base64 encode/decode, or hex encode/decode. For files it reads and writes byte streams to avoid character-encoding issues, and for text it operates on UTF-8 by default. Command flags control mode (encode/decode), target format, URL-safe output, and file paths for input or output.

When to use it

  • Embed binary data in text formats (JSON, YAML, CSV)
  • Generate URL-safe tokens or payloads for web use
  • Decode incoming Base64 or hex-encoded responses
  • Serialize small files or images into text fields
  • Quick CLI conversions during development or debugging

Best practices

  • Prefer file mode for non-text binary data to avoid encoding errors with large files
  • Use URL-safe Base64 when placing tokens in URLs or cookies
  • Validate decoded output type (text vs binary) before further processing
  • Avoid using Base64 for large file transmission—use it for small payloads or metadata only
  • Keep explicit flags for encode/decode and format to prevent accidental double-encoding

Example use cases

  • Encode a short string for inclusion in a JSON payload: encode "Hello World" to Base64
  • Convert an image to a Base64 file for embedding in HTML: encode --file image.png --output image.b64
  • Decode an API response that returns a hex string into raw bytes for processing
  • Create a URL-safe token: encode "session-data" --url-safe and include the result in a link
  • Batch-decode a set of Base64 files to recover original binary assets

FAQ

Does this support streaming large files?

Yes. The tool reads and writes byte streams for file operations to avoid loading entire files into memory when possible.

What encoding does it assume for text input?

Text input is treated as UTF-8 when converting to or from Base64 or hex.

How do I create URL-safe Base64 output?

Use the URL-safe flag when encoding; the tool substitutes URL-friendly characters and strips padding if specified.