From harness-claude
Handles Node.js Buffer for binary data: creation, encoding conversions (UTF-8, Base64, hex), TextEncoder/Decoder, operations, read/write numbers. For file I/O, networks, crypto.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Handle binary data, encodings, and conversions with Node.js Buffer and TextEncoder
Encodes and decodes Base64, URL-safe Base64, and hexadecimal strings via Python CLI, with file input/output support. Useful for binary-text conversion, data embedding, or debugging. Triggers on /base64 or encoding needs.
Processes large data efficiently using Node.js Readable, Writable, Transform streams and pipelines for file I/O, data transformation, HTTP responses, and backpressure handling.
Provides Node.js best practices with TypeScript via type stripping (Node 22+), covering async patterns, error handling, streams, modules, testing, performance, caching, logging. For native TS setups, graceful shutdown, flaky tests, and env config.
Share bugs, ideas, or general feedback.
Handle binary data, encodings, and conversions with Node.js Buffer and TextEncoder
const fromString = Buffer.from('Hello, world!', 'utf-8');
const fromHex = Buffer.from('48656c6c6f', 'hex');
const fromBase64 = Buffer.from('SGVsbG8=', 'base64');
const allocated = Buffer.alloc(1024); // Zero-filled
const unsafe = Buffer.allocUnsafe(1024); // Uninitialized (faster)
const buf = Buffer.from('Hello');
buf.toString('utf-8'); // 'Hello'
buf.toString('hex'); // '48656c6c6f'
buf.toString('base64'); // 'SGVsbG8='
buf.toString('base64url'); // 'SGVsbG8' (URL-safe base64)
const encoder = new TextEncoder();
const decoder = new TextDecoder('utf-8');
const encoded = encoder.encode('Hello'); // Uint8Array
const decoded = decoder.decode(encoded); // 'Hello'
// Concatenate
const combined = Buffer.concat([buf1, buf2, buf3]);
// Slice (shares memory — modifications affect the original)
const slice = buf.subarray(0, 5);
// Copy (independent copy)
const copy = Buffer.from(buf);
// Compare
buf1.equals(buf2); // true/false
Buffer.compare(buf1, buf2); // -1, 0, or 1
const buf = Buffer.alloc(8);
buf.writeUInt32BE(0x12345678, 0); // Big-endian at offset 0
buf.writeUInt32LE(0x12345678, 4); // Little-endian at offset 4
const val = buf.readUInt32BE(0); // 0x12345678
function toBase64(data: string): string {
return Buffer.from(data, 'utf-8').toString('base64');
}
function fromBase64(encoded: string): string {
return Buffer.from(encoded, 'base64').toString('utf-8');
}
// URL-safe base64
function toBase64Url(data: string): string {
return Buffer.from(data).toString('base64url');
}
const buffer = Buffer.from([1, 2, 3, 4]);
const uint8 = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
// Buffer IS a Uint8Array subclass
buffer instanceof Uint8Array; // true
Buffer is Node.js's primary type for handling binary data. It is a subclass of Uint8Array with additional methods for encoding conversion and binary manipulation.
Encoding options: utf-8 (default), ascii, latin1, binary, hex, base64, base64url, ucs-2/utf-16le.
Buffer vs Uint8Array: Buffer extends Uint8Array but adds Node.js-specific methods (toString(encoding), write(), readInt32BE()). Web APIs use Uint8Array; Node.js APIs accept both.
Memory considerations:
Buffer.alloc(n) — zero-filled, safe, slightly slowerBuffer.allocUnsafe(n) — may contain old memory data, faster. Only use when you will overwrite all bytesBuffer.from(array) — allocates new memory and copies dataTrade-offs:
subarray — but mutations affect the original (use Buffer.from(buf) for independent copies)allocUnsafe is faster — but can leak sensitive data if not fully overwrittenhttps://nodejs.org/api/buffer.html