https://github.com/rails/marcel
Find the mime type of files, examining file, filename and declared type
https://github.com/rails/marcel
Keywords from Contributors
activerecord activejob mvc rubygems rack rspec gem ruby-gem feature-flag multithreading
Last synced: about 21 hours ago
JSON representation
Repository metadata
Find the mime type of files, examining file, filename and declared type
- Host: GitHub
- URL: https://github.com/rails/marcel
- Owner: rails
- License: apache-2.0
- Created: 2017-02-22T20:02:09.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2026-01-23T20:33:01.000Z (about 1 month ago)
- Last Synced: 2026-02-24T00:05:06.654Z (8 days ago)
- Language: Ruby
- Size: 5.06 MB
- Stars: 435
- Watchers: 26
- Forks: 77
- Open Issues: 35
- Releases: 9
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
README.md
Marcel
Marcel chooses the most appropriate content type for a file by inspecting its contents, the declared MIME type (perhaps passed as a Content-Type header), and the file extension.
Marcel checks, in order:
- The "magic bytes" sniffed from the file contents.
- The declared type, typically provided in a Content-Type header on an uploaded file, unless it's the
application/octet-streamdefault. - The filename extension.
- Safe fallback to the indeterminate
application/octet-streamdefault.
At each step, the most specific MIME subtype is selected. This allows the declared type and file extension to refine the parent type sniffed from the file contents, but not conflict with it. For example, if "file.csv" has declared type text/plain, text/csv is returned since it's a more specific subtype of text/plain. Similarly, Adobe Illustrator files are PDFs internally, so magic byte sniffing indicates application/pdf which is refined to application/illustrator by the ai file extension. But a PDF named "image.png" will still be detected as application/pdf since image/png is not a subtype.
Usage
# Magic bytes sniffing alone
Marcel::MimeType.for Pathname.new("example.gif")
# => "image/gif"
File.open "example.gif" do |file|
Marcel::MimeType.for file
end
# => "image/gif"
# Magic bytes with filename fallback
Marcel::MimeType.for Pathname.new("unrecognisable-data"), name: "example.pdf"
# => "application/pdf"
# File extension alone
Marcel::MimeType.for extension: ".pdf"
# => "application/pdf"
# Magic bytes, declared type, and filename together
Marcel::MimeType.for Pathname.new("unrecognisable-data"), name: "example", declared_type: "image/png"
# => "image/png"
# Safe fallback to application/octet-stream
Marcel::MimeType.for StringIO.new(File.read "unrecognisable-data")
# => "application/octet-stream"
Extending
Custom file types may be added with Marcel::MimeType.extend:
Marcel::MimeType.extend "text/custom", extensions: %w( customtxt )
Marcel::MimeType.for name: "file.customtxt"
# => "text/custom"
Motivation
Marcel was extracted from Basecamp's file detection heuristics. The aim is provide sensible, safe, "do what I expect" results for typical file handling. Test fixtures have been added for many common file types, including those typically encountered by Basecamp.
Contributing
Marcel generates MIME lookup tables with bundle exec rake update. MIME types are seeded from data found in data/*.xml. Custom MIMEs may be added to data/custom.xml, while overrides to the standard MIME database may be added to lib/marcel/mime_type/definitions.rb.
Marcel follows the same contributing guidelines as rails/rails.
Testing
The main test fixture files are split into two folders, those that can be recognised by magic bytes, and those that can only be recognised by name. Even though strictly unnecessary, the fixtures in both folders should all be valid files of the type they represent.
License
Marcel itself is released under the terms of the MIT License. See the MIT-LICENSE file for details.
Portions of Marcel are adapted from the mimemagic gem, released under the terms of the MIT License.
Marcel's magic signature data is adapted from Apache Tika, released under the terms of the Apache License. See the APACHE-LICENSE file for details.
Owner metadata
- Name: Ruby on Rails
- Login: rails
- Email:
- Kind: organization
- Description:
- Website: https://rubyonrails.org/
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/4223?v=4
- Repositories: 116
- Last ynced at: 2023-04-09T03:40:20.529Z
- Profile URL: https://github.com/rails
GitHub Events
Total
- Delete event: 1
- Pull request event: 7
- Fork event: 5
- Issues event: 12
- Watch event: 35
- Issue comment event: 15
- Push event: 6
- Pull request review event: 7
- Pull request review comment event: 6
- Create event: 3
Last Year
- Delete event: 1
- Pull request event: 7
- Fork event: 3
- Issues event: 7
- Watch event: 29
- Issue comment event: 9
- Push event: 6
- Pull request review event: 7
- Pull request review comment event: 6
- Create event: 3
Committers metadata
Last synced: 3 days ago
Total Commits: 149
Total Committers: 34
Avg Commits per committer: 4.382
Development Distribution Score (DDS): 0.638
Commits in past year: 7
Committers in past year: 3
Avg Commits per committer in past year: 2.333
Development Distribution Score (DDS) in past year: 0.286
| Name | Commits | |
|---|---|---|
| Tom Ward | t****m@p****t | 54 |
| Jeremy Daer | j****y@r****g | 17 |
| George Claghorn | g****e@b****m | 16 |
| Gannon McGibbon | g****n@g****m | 15 |
| Jean Boussier | j****r@g****m | 6 |
| Rafael Mendonça França | r****l@r****g | 5 |
| Jun Aruga | j****a@r****m | 3 |
| Andy Nguyen | a****n@s****m | 2 |
| Brian Kephart | b****t@g****m | 2 |
| Chris Oliver | e****3@g****m | 2 |
| Olle Jonsson | o****n@g****m | 2 |
| dependabot[bot] | 4****] | 2 |
| Eddie Lebow | E****w@p****m | 2 |
| yuuji.yaginuma | y****a@g****m | 1 |
| wonda-tea-coffee | l****t@g****m | 1 |
| mark-young-atg | 1****g | 1 |
| eileencodes | e****s@g****m | 1 |
| Vipul A M | v****d@g****m | 1 |
| Valeriy Mironov | v****m@g****m | 1 |
| Stano Bo | sb@j****t | 1 |
| Mth0158 | m****y@g****m | 1 |
| Marcel Eeken | m****n@y****l | 1 |
| Koza | k****a@g****m | 1 |
| Koji Onishi | f****0@g****m | 1 |
| Keita Urashima | u****m@u****p | 1 |
| Alberto Fernandez-Capel | a****o@h****m | 1 |
| Alexander Gitter | c****t@a****t | 1 |
| Andrew Nutter-Upham | a****u@g****m | 1 |
| Ben Koshy | b****y@h****m | 1 |
| Cẩm Huỳnh | h****m@g****m | 1 |
| and 4 more... | ||
Committer domains:
- rubyonrails.org: 2
- frances.co: 1
- agitter.net: 1
- hey.com: 1
- ursm.jp: 1
- youngcapital.nl: 1
- juniq.net: 1
- phishme.com: 1
- shopify.com: 1
- redhat.com: 1
- basecamp.com: 1
- popdog.net: 1
Issue and Pull Request metadata
Last synced: 18 days ago
Total issues: 54
Total pull requests: 93
Average time to close issues: 7 months
Average time to close pull requests: 3 months
Total issue authors: 53
Total pull request authors: 45
Average comments per issue: 2.04
Average comments per pull request: 0.89
Merged pull request: 58
Bot issues: 0
Bot pull requests: 3
Past year issues: 8
Past year pull requests: 18
Past year average time to close issues: 2 months
Past year average time to close pull requests: about 1 month
Past year issue authors: 8
Past year pull request authors: 5
Past year average comments per issue: 0.75
Past year average comments per pull request: 0.89
Past year merged pull request: 5
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- tomafro (2)
- tomhughes (1)
- markedmondson (1)
- IBazylchuk (1)
- genezys (1)
- AlfonsoUceda (1)
- nvanoorschot (1)
- timfrazee (1)
- ClearlyClaire (1)
- gr8bit (1)
- pcantrell (1)
- ron-shinall (1)
- andyvanee (1)
- ocarreterom (1)
- mdavidn (1)
Top Pull Request Authors
- gmcgibbon (11)
- alexanderadam (10)
- jeremy (5)
- junaruga (4)
- rafaelfranca (4)
- hahmed (3)
- casperisfine (3)
- georgeclaghorn (3)
- dependabot[bot] (3)
- trekdemo (2)
- sjoulbak (2)
- olleolleolle (2)
- alexandergitter (2)
- mark-young-atg (2)
- FrancescoK (2)
Top Issue Labels
Top Pull Request Labels
- dependencies (3)
Package metadata
- Total packages: 4
-
Total downloads:
- rubygems: 845,786,494 total
- Total docker downloads: 5,984,095,580
- Total dependent packages: 48 (may contain duplicates)
- Total dependent repositories: 290,032 (may contain duplicates)
- Total versions: 30
- Total maintainers: 12
gem.coop: marcel
Simple mime type detection using magic numbers, filenames, and extensions
- Homepage: https://github.com/rails/marcel
- Documentation: http://www.rubydoc.info/gems/marcel/
- Licenses: MIT,Apache-2.0
- Latest release: 1.1.0 (published 6 months ago)
- Last Synced: 2026-02-28T14:00:34.177Z (3 days ago)
- Versions: 10
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 422,893,247 Total
- Docker Downloads: 2,992,047,790
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.026%
- Docker downloads count: 0.045%
- Downloads: 0.058%
- Maintainers (12)
debian-13: ruby-marcel
- Homepage: https://github.com/rails/marcel
- Documentation: https://packages.debian.org/trixie/ruby-marcel
- Licenses: apache-2.0
- Latest release: 1.0.4+dfsg-2 (published 19 days ago)
- Last Synced: 2026-02-13T13:17:23.084Z (18 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.336%
- Forks count: 0.605%
- Stargazers count: 0.738%
rubygems.org: marcel
Simple mime type detection using magic numbers, filenames, and extensions
- Homepage: https://github.com/rails/marcel
- Documentation: http://www.rubydoc.info/gems/marcel/
- Licenses: MIT,Apache-2.0
- Latest release: 1.1.0 (published 6 months ago)
- Last Synced: 2026-02-28T13:31:50.644Z (3 days ago)
- Versions: 10
- Dependent Packages: 48
- Dependent Repositories: 290,032
- Downloads: 422,893,247 Total
- Docker Downloads: 2,992,047,790
-
Rankings:
- Downloads: 0.069%
- Docker downloads count: 0.069%
- Dependent repos count: 0.084%
- Dependent packages count: 0.611%
- Average: 1.19%
- Stargazers count: 2.948%
- Forks count: 3.361%
- Maintainers (12)
proxy.golang.org: github.com/rails/marcel
- Homepage:
- Documentation: https://pkg.go.dev/github.com/rails/marcel#section-documentation
- Licenses: apache-2.0
- Latest release: v1.1.0 (published 6 months ago)
- Last Synced: 2026-02-27T22:01:49.775Z (4 days ago)
- Versions: 9
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 2.964%
- Forks count: 3.095%
- Average: 6.609%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
Dependencies
- bundler >= 1.7 development
- byebug ~> 10.0.2 development
- minitest ~> 5.11 development
- nokogiri >= 1.9.1 development
- rack ~> 2.0 development
- rake ~> 13.0 development
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
Score: 32.32370936202453