magic
Version, currently 1.1.02 versions
- 1.1.0latestJun 22, 2020
- 1.0.0not indexedJun 1, 2021
github.com/dscottboggs/magic.cr
Bindings for libmagic to Crystal
10 stars
2 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
magic:
github: dscottboggs/magic.cr
version: ~> 1.1.0Then run:
shards installshard.yml
- Crystal
0.35.0- License
- MIT
- Author
- D. Scott Boggs <scott@tams.tech>
Dependencies
Development Dependencies
- ameba*github: crystal-ameba/amebadev
README
[](https://cloud.drone.io/dscottboggs/magic.cr)
# magic.cr
Bindings to `libmagic(2)` for Crystal.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
magic:
github: dscottboggs/magic.cr
```
## Usage
[API documentation](https://dscottboggs.github.io/magic.cr/index.html)
```crystal
require "magic"
require "http" # for the HTTP example
TestImageURL = "https://upload.wikimedia.org/wikipedia/commons/d/db/Patern_test.jpg"
# get a description of the contents of the file at a path.
Magic.filetype.of "/path/to/a/video.mkv" # => "Matroska data"
# open your bashrc and check its mime type
File.open "~/.bashrc" do |bashrc|
Magic.mime_type.of bashrc # => "text/plain"
end
# pull TestImageURL from the web and find out what the valid extensions are for
# the bytes received.
HTTP::Client.get TestImageURL do |result|
Magic.filetype.extensions result.body_io # => Set{"jpeg", "jpg", "jpe", "jfif"}
end
# change a setting and check a filetype
dir = Dir.open "/dev/disk/by-uuid"
dir.each_child do |symlink|
Magic.filetype.of symlink # => "symlink to /dev/sdXX"
end
dir.each_child do |symlink|
Magic.filetype.follow_symlinks.for symlink # => "block special..."
end
```
There is also a much more flexible and complicated API for more advanced usage.
For more information and some examples, see `Magic::TypeChecker` and
`spec/magic.cr_spec.cr`.
## Development
Create an issue if you think anything needs revision!
## Contributing
1. Fork it (<https://github.com/dscottboggs/magic.cr/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [dscottboggs](https://github.com/dscottboggs) D. Scott Boggs - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
1.1.0- Tagged
- Jun 22, 2020
- Commit
67d574407218- Crystal
0.35.0- Indexed
- yes
Dependents
Repository
github.com/dscottboggs/magic.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 2