A summary of data about the Ruby ecosystem.

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

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:

  1. The "magic bytes" sniffed from the file contents.
  2. The declared type, typically provided in a Content-Type header on an uploaded file, unless it's the application/octet-stream default.
  3. The filename extension.
  4. Safe fallback to the indeterminate application/octet-stream default.

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


GitHub Events

Total
Last Year

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 Email 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:


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

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/rails/marcel

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

gem.coop: marcel

Simple mime type detection using magic numbers, filenames, and extensions

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

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

marcel.gemspec rubygems
  • 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
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems

Score: 32.32370936202453