Add support for conversion from any format#92
Merged
p2r3 merged 2 commits intop2r3:masterfrom Feb 16, 2026
Merged
Conversation
Closed
Owner
|
How did you test this? |
Contributor
Author
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."; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#87