magic
Version, currently 1.0.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
Nothing has been indexed for 1.0.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
magic:
github: dscottboggs/magic.cr
version: ~> 1.0.0Then run:
shards installshard.yml
No shard.yml has been indexed for 1.0.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
[](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.0.0- Tagged
- Jun 1, 2021
- Commit
bfa4998d9576- Indexed
- not yet
Dependents
Repository
github.com/dscottboggs/magic.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 2