https://github.com/sixarm/sixarm_ruby_magic_number_type
SixArm.com » Ruby » MagicNumberType infers a data type from the data's leading bytes
https://github.com/sixarm/sixarm_ruby_magic_number_type
gem magic-number mime-types ruby
Last synced: about 1 year ago
JSON representation
SixArm.com » Ruby » MagicNumberType infers a data type from the data's leading bytes
- Host: GitHub
- URL: https://github.com/sixarm/sixarm_ruby_magic_number_type
- Owner: SixArm
- License: other
- Created: 2011-02-07T09:48:55.000Z (about 15 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T09:19:12.000Z (about 1 year ago)
- Last Synced: 2025-04-14T10:29:46.498Z (about 1 year ago)
- Topics: gem, magic-number, mime-types, ruby
- Language: Ruby
- Homepage: http://sixarm.com
- Size: 515 KB
- Stars: 13
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# SixArm.com → Ruby →
MagicNumberType infers mime types from leading bits
[](http://badge.fury.io/rb/sixarm_ruby_magic_number_type)
[](https://travis-ci.org/SixArm/sixarm_ruby_magic_number_type)
[](https://codeclimate.com/github/SixArm/sixarm_ruby_magic_number_type/maintainability)
* Git:
* Doc:
* Gem:
* Contact: Joel Parker Henderson,
* Project: [changes](CHANGES.md), [license](LICENSE.md), [contributing](CONTRIBUTING.md).
## Introduction
Magic numbers are the first bits of a file or data stream
which uniquely identify the type of file or data stream.
For example when the first bits are "BM",
this identifies the file as a bitmap image file.
For docs go to
Want to help? We're happy to get pull requests.
## Install
### Gem
To install this gem in your shell or terminal:
gem install sixarm_ruby_magic_number_type
### Gemfile
To add this gem to your Gemfile:
gem 'sixarm_ruby_magic_number_type'
### Require
To require the gem in your code:
require 'sixarm_ruby_magic_number_type'
## Details
This gem infers based on widespread programming conventions for data file formats.
These magic numbers are by convention and we are using this guide:
http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html
Typical uses of magic numbers:
* to quickly identify a file's data type
* to check if data matches the file's MIME type or extension
* to check if a web form file upload matches its HTTP content type
Compare:
* MIME::Types ruby library
* Unix magic() command for testing files on disk
* http://shared-mime.rubyforge.org/
## Contributors
* [Joel Parker Henderson](https://github.com/joelparkerhenderson)
* [Bill Lazar](https://github.com/billlazar)
* [Kip Cole](https://github.com/kipcole9)