javascript-binary-converter
Version:
A utility package to quickly handle and convert various Javascript binary objects
21 lines • 894 B
JavaScript
import { isNode } from "../utils/crossPlatform";
import { binaryToImage } from "../utils/image";
import BlobConverter from "./BlobConverter";
export default class FileConverter extends BlobConverter {
constructor(original) {
super(original);
if (isNode)
throw new Error('FileConvertor is available only in the browser');
}
/**
* Convert a File object to an image, whose src is a Blob.
* Optionally supply a config object with maxSize, refering to the maximal height or width(depending on the proportions).
*/
async toImage(config) {
if (config?.validateImage !== false && !this.original.type.match(/image.*/)) {
throw new Error('File supplied is not an image');
}
return binaryToImage(this.original, config ? config : undefined);
}
}
//# sourceMappingURL=FileConverter.js.map