class
Athena::MIME::Types
- Athena::MIME::Types
- Reference
- Object
Overview
Default implementation of AMIME::TypesInterface
.
Also supports guessing a MIME type based on a given file path.
Custom guessers can be registered via the #register_guesser
method.
Custom guessers are always called before any default ones.
mime_types = AMIME::Types.new
mime_types.mime_types "png" # => {"image/png", "image/apng", "image/vnd.mozilla.apng"}
mime_types.extensions "image/png" # => {"png"}
mime_types.guess_mime_type "/path/to/image.png" # => "image/png"
Included Modules
Defined in:
types.crtypes/data.cr
Constructors
-
.default : self
Returns/sets the default singleton instance.
- .new(map : Hash(String, Enumerable(String)) = Map.new)
Class Method Summary
-
.default=(default : self)
Returns/sets the default singleton instance.
Instance Method Summary
-
#extensions(for mime_type : String) : Enumerable(String)
Returns the valid file extensions for the provided mime_type in decreasing order of preference.
-
#guess_mime_type(path : String | Path) : String | Nil
Returns the guessed MIME type for the file at the provided path, or
nil
if it could not be determined. -
#mime_types(for extension : String) : Enumerable(String)
Returns the valid MIME types for the provided extension in decreasing order of preference.
-
#register_guesser(guesser : AMIME::TypesGuesserInterface) : Nil
Registers the provided guesser.
-
#supported? : Bool
Returns
true
if this guesser is supported, otherwisefalse
.
Instance methods inherited from module Athena::MIME::TypesInterface
extensions(for mime_type : String) : Enumerable(String)
extensions,
mime_types(for extension : String) : Enumerable(String)
mime_types
Instance methods inherited from module Athena::MIME::TypesGuesserInterface
guess_mime_type(path : String | Path) : String | Nil
guess_mime_type,
supported? : Bool
supported?
Constructor Detail
Class Method Detail
Instance Method Detail
Returns the valid file extensions for the provided mime_type in decreasing order of preference.
types.extensions "image/png" # => {"png"}
Returns the guessed MIME type for the file at the provided path,
or nil
if it could not be determined.
How exactly the MIME type is determined is up to each individual implementation.
guesser.guess_mime_type "/path/to/image.png" # => "image/png"
Returns the valid MIME types for the provided extension in decreasing order of preference.
types.mime_types "png" # => {"image/png", "image/apng", "image/vnd.mozilla.apng"}
Registers the provided guesser. The last registered guesser is preferred over previously registered ones.
Returns true
if this guesser is supported, otherwise false
.
The value may be cached on the class level.