-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to register third-party extensions #399
Conversation
@@ -268,6 +268,16 @@ Returns a set of supported file extensions. | |||
|
|||
Returns a set of supported MIME types. | |||
|
|||
### FileType.addDetection(detection) | |||
|
|||
Register a detection function. This function will be called after `file-type` and other detections complete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other detections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proprietary software file extensions that are not well known. The use case would be a file that could be standard MIME type or proprietary/used-defined MIME types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even plain text files that the users will be willing to support. Say, there's not enough confidence to be able to detect an svg or HTML to include it in the core, but the users could accept that and provide their own detection which will be enough for their use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the whole point of this PR. That's not what I'm asking. I'm saying that "other detections" is not clear enough in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "other" is probably intended to leave it open for extension. Examples could be provided but are probably not going to be exhaustive. Perhaps what you're asking for is some examples? That was the point of my comment and others.
- [tokenizer](https://github.com/Borewit/strtok3#tokenizer) | ||
- `fileType`, which is `undefined` or the return value of a detected file type. | ||
|
||
If the detector returns `undefined`, the `tokenizer.position` should be 0. That allows other detectors to parse the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why cannot file-type
reset the position automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because underlying source can be a stream. A stream can only be read once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it should be made clear that the
tokenizer.position should be 0
should not be done if it's a stream.
|
||
type Detection = (tokenizer: ITokenizer, fileType? : core.FileTypeResult) => Promise<core.FileTypeResult | undefined>; | ||
|
||
function addDetection(detection: Detection): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs the same docs as the readme.
Sorry I am a bit unresponsive this time. I very busy at the moment. Thanks for all your feedback. |
Gentle bump in case you have time and just forgot about this. If you're still busy, feel free to ignore. |
I'm going to close this as it has been open for a very long time without any activity. A new PR can be opened if when/if you get back to this ;) |
FileType.addDetection(detection)
Register a detection function. This function fill be called after the file-type, and other detections completed.
the
detection(tokenizer, fileType)
method has two arguments:fileType
, which isundefined
or the return value of a detected file type.Resolves #340.
Issues: