-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,7 @@ export { | |
fromTokenizer, | ||
extensions, | ||
mimeTypes, | ||
stream | ||
stream, | ||
Detection, | ||
addDetection | ||
} from './core'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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. |
||
|
||
The `detection(tokenizer, fileType)` method has two arguments: | ||
- [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 commentThe reason will be displayed to describe this comment to others. Learn more. Why cannot There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Then it should be made clear that |
||
|
||
## Supported file types | ||
|
||
- [`jpg`](https://en.wikipedia.org/wiki/JPEG) | ||
|
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.