sindresorhus/file-type

Missing fileTypeOptions for `fileTypeFromStream` function in index declaration file

sly7-7 opened this issue ยท 6 comments

Description

The options with customDetectors are missing in the declaration file, see:

export function fileTypeFromStream(stream: AnyWebReadableStream<Uint8Array> | NodeReadableStream): Promise<FileTypeResult | undefined>;

Existing Issue Check

  • I have searched the existing issues and could not find any related to my problem.

ESM (ECMAScript Module) Requirement Acknowledgment

  • My project is an ESM project and my package.json contains the following entry: "type": "module".

File-Type Scope Acknowledgment

  • I understand that file-type detects binary file types and not text or other formats.

Also, I've noted that the exported functions from core.js don't have the detectors in their signatures. Maybe this was on purpose ? In my use case then, I've used straight the FileTypeParser() constructor passing it a detector.
Please let me know if this is the right way, or if you would accept a pr with the detectors available in core.js.

The options are not missing from the types, the options can only be passed via the constructor. Which may like or not like, but that is not a bug.

My philosophy behind was something like, if you do want to change the default behavior of file-type, you probably do not mind to call the constructor. That way you can also reuse the customized instance, for assessing multiple files.

To me it feels a bit odd if each function passes the options to the constructor. Then we also have repeat the documentation for it. But I also see it may appear a bit more convenient.

Thank your for your answer, I understand your philosophy, and if I understand it well, then I'm doing what's intended ๐Ÿ˜ƒ

One thing though, unless I'm missing something else (which can be very possible ๐Ÿ˜… ), there is an inconsistency between index.js where fileTypeOptionsis in the signature

export async function fileTypeFromStream(stream, fileTypeOptions) {

whereas it does not appear in index.d.ts:

export function fileTypeFromStream(stream: AnyWebReadableStream<Uint8Array> | NodeReadableStream): Promise<FileTypeResult | undefined>;

Also I've just noticed an other small thing looking weird to me:

return (new FileTypeParser(fileTypeOptions)).fromFile(path, fileTypeOptions);

fileTypeOptions beeing passed to fromFile(), but

async fromFile(path) {

does not use it.

One more time, maybe I'm totally wrong and I just don't read the code correctly, but if I'm right, I could make a PR to remove these inconsistencies.

Sorry for my late reply @sly7-7 , it is not consistent at all, you are totally right.

Please do!

No worries for the delay, thank you for the answer ๐Ÿ˜Š. I'll do that tomorrow.