mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-03 04:54:26 +00:00
- yapf_encode() / yapf_free_buffer(): encode to memory; yapf_save uses it - yapf.c also compiles as C++ - `yapf compare`: size and decode speed of the original format vs YAPF, with a lossless check - bindings with tested examples: C++ (header-only), C# (P/Invoke), Rust (crate, builds the C code), Go (cgo), Java (FFM API, Java 22+), Zig (@cImport), LuaJIT (FFI), TypeScript types for the JS port; Python now encodes in memory - docs/LANGUAGES.md and examples/ with measured results - KDE Dolphin thumbnail plugin (KF6, CMake) - README: honest status for Photoshop / VS Code / Figma (not run in the apps yet) and macOS (cross-compiled only), platform table Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19 lines
915 B
JavaScript
19 lines
915 B
JavaScript
// node example.mjs ../../other/YAPF.YAPF
|
|
import { readFileSync } from 'node:fs';
|
|
import { createRequire } from 'node:module';
|
|
const YAPF = createRequire(import.meta.url)('./yapf.js');
|
|
|
|
const path = process.argv[2] ?? '../../other/YAPF.YAPF';
|
|
const file = readFileSync(path);
|
|
|
|
let img = YAPF.decode(file);
|
|
let best = Infinity; // best of 10 decodes
|
|
for (let i = 0; i < 10; i++) {
|
|
const t = performance.now();
|
|
img = YAPF.decode(file);
|
|
best = Math.min(best, performance.now() - t);
|
|
}
|
|
console.log(`${path}: ${img.width}x${img.height}, ${img.channels} channels, decoded in ${best.toFixed(2)} ms (pure JavaScript)`);
|
|
console.log(`file is ${file.length} bytes, ${(100 * file.length / img.pixels.length).toFixed(1)}% of the raw pixels`);
|
|
const again = YAPF.encode(img);
|
|
console.log(`re-encoded: ${again.length} bytes, identical: ${Buffer.compare(Buffer.from(again), file) === 0}`);
|