roxify 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync, writeFileSync } from 'fs';
3
3
  import { basename, dirname, resolve } from 'path';
4
- import sharp from 'sharp';
5
- import { cropAndReconstitute, DataFormatError, decodePngToBinary, encodeBinaryToPng, IncorrectPassphraseError, PassphraseRequiredError, } from './index.js';
6
- const VERSION = '1.0.4';
4
+ import { DataFormatError, decodePngToBinary, encodeBinaryToPng, IncorrectPassphraseError, PassphraseRequiredError, } from './index.js';
5
+ const VERSION = '1.1.4';
7
6
  function showHelp() {
8
7
  console.log(`
9
8
  ROX CLI — Encode/decode binary in PNG
@@ -167,7 +166,6 @@ async function decodeCommand(args) {
167
166
  try {
168
167
  const inputBuffer = readFileSync(resolvedInput);
169
168
  console.log(`Reading: ${resolvedInput}`);
170
- const info = await sharp(inputBuffer).metadata();
171
169
  const options = {};
172
170
  if (parsed.passphrase) {
173
171
  options.passphrase = parsed.passphrase;
@@ -177,18 +175,7 @@ async function decodeCommand(args) {
177
175
  }
178
176
  console.log(`Decoding...`);
179
177
  const startDecode = Date.now();
180
- if (parsed.verbose)
181
- options.verbose = true;
182
- const doubledBuffer = await sharp(inputBuffer)
183
- .resize({
184
- width: info.width * 2,
185
- height: info.height * 2,
186
- kernel: 'nearest',
187
- })
188
- .png()
189
- .toBuffer();
190
- const reconstructedBuffer = await cropAndReconstitute(doubledBuffer, options.debugDir);
191
- const result = await decodePngToBinary(reconstructedBuffer, options);
178
+ const result = await decodePngToBinary(inputBuffer, options);
192
179
  const decodeTime = Date.now() - startDecode;
193
180
  const resolvedOutput = parsed.output || outputPath || result.meta?.name || 'decoded.bin';
194
181
  writeFileSync(resolvedOutput, result.buf);
package/dist/index.js CHANGED
@@ -650,8 +650,24 @@ export async function encodeBinaryToPng(input, opts = {}) {
650
650
  * @public
651
651
  */
652
652
  export async function decodePngToBinary(pngBuf, opts = {}) {
653
- if (pngBuf.slice(0, MAGIC.length).equals(MAGIC)) {
654
- const d = pngBuf.slice(MAGIC.length);
653
+ let processedBuf = pngBuf;
654
+ try {
655
+ const info = await sharp(pngBuf).metadata();
656
+ if (info.width && info.height) {
657
+ const doubledBuffer = await sharp(pngBuf)
658
+ .resize({
659
+ width: info.width * 2,
660
+ height: info.height * 2,
661
+ kernel: 'nearest',
662
+ })
663
+ .png()
664
+ .toBuffer();
665
+ processedBuf = await cropAndReconstitute(doubledBuffer, opts.debugDir);
666
+ }
667
+ }
668
+ catch (e) { }
669
+ if (processedBuf.slice(0, MAGIC.length).equals(MAGIC)) {
670
+ const d = processedBuf.slice(MAGIC.length);
655
671
  const nameLen = d[0];
656
672
  let idx = 1;
657
673
  let name;
@@ -678,7 +694,7 @@ export async function decodePngToBinary(pngBuf, opts = {}) {
678
694
  }
679
695
  let chunks = [];
680
696
  try {
681
- const chunksRaw = extract(pngBuf);
697
+ const chunksRaw = extract(processedBuf);
682
698
  chunks = chunksRaw.map((c) => ({
683
699
  name: c.name,
684
700
  data: Buffer.isBuffer(c.data)
@@ -731,7 +747,7 @@ export async function decodePngToBinary(pngBuf, opts = {}) {
731
747
  return { buf: payload, meta: { name } };
732
748
  }
733
749
  try {
734
- const { data, info } = await sharp(pngBuf)
750
+ const { data, info } = await sharp(processedBuf)
735
751
  .ensureAlpha()
736
752
  .raw()
737
753
  .toBuffer({ resolveWithObject: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxify",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Encode binary data into PNG images with Zstd compression and decode them back. Supports CLI and programmatic API (Node.js ESM).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",