Skip to content

Add support for conversion from any format#92

Merged
p2r3 merged 2 commits intop2r3:masterfrom
piotrstenke:feature/any-from-conversion
Feb 16, 2026
Merged

Add support for conversion from any format#92
p2r3 merged 2 commits intop2r3:masterfrom
piotrstenke:feature/any-from-conversion

Conversation

@piotrstenke
Copy link
Copy Markdown
Contributor

#87

@p2r3
Copy link
Copy Markdown
Owner

p2r3 commented Feb 16, 2026

How did you test this?

@piotrstenke
Copy link
Copy Markdown
Contributor Author

piotrstenke commented Feb 16, 2026

How did you test this?

I'm making a ZIP converter mentioned in #95, so I've tested with that, but a simple example would like this:

anyHandler.ts

import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";

class anyHandler implements FormatHandler {
  public name: string = "any";

  public supportedFormats: FileFormat[] = [
    {
      name: "ZIP Archive",
      format: "zip",
      extension: "zip",
      mime: "application/zip",
      from: false,
      to: true,
      internal: "zip"
    }
  ];

  public supportAnyInput: boolean = true;

  public ready: boolean = false;

  async init() {
    this.ready = true;
  }

  async doConvert(
    inputFiles: FileData[],
    inputFormat: FileFormat,
    outputFormat: FileFormat
  ): Promise<FileData[]> {
    return [{ name: "test.zip", bytes: new Uint8Array([0, 1]) }];
  }
}

export default anyHandler;

index.ts

try { handlers.push(new anyHandler()); } catch (_) { };

If you try to convert to ZIP from format listed in 'renameHandler' (e.g. xlsx), the 'renameHandler' will be used as usual. If you try with e.g. a png file, no direct path is found, so it fallbacks to this 'anyHandler'.

To test this you must temporarily comment out line 148 in rename.ts, as right now it throws an error for non-zip files.

if (inputFormat.internal !== "zip") throw "Invalid input format.";

@p2r3 p2r3 merged commit 83b72fe into p2r3:master Feb 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants