{"id":16945174,"url":"https://github.com/rafbm/fileinfo","last_synced_at":"2025-04-11T15:32:19.379Z","repository":{"id":10502358,"uuid":"12686978","full_name":"rafbm/fileinfo","owner":"rafbm","description":"FileInfo detects file encodings and MIME types using the wonderful Unix `file` command.","archived":false,"fork":false,"pushed_at":"2017-02-11T12:54:41.000Z","size":45,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T15:35:15.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-08T20:21:58.000Z","updated_at":"2025-02-25T08:50:09.000Z","dependencies_parsed_at":"2022-09-09T01:00:29.693Z","dependency_job_id":null,"html_url":"https://github.com/rafbm/fileinfo","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Ffileinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Ffileinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Ffileinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Ffileinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafbm","download_url":"https://codeload.github.com/rafbm/fileinfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248116318,"owners_count":21050373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T21:21:25.070Z","updated_at":"2025-04-11T15:32:19.136Z","avatar_url":"https://github.com/rafbm.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FileInfo\n\n[![Gem Version](https://badge.fury.io/rb/fileinfo.png)](http://badge.fury.io/rb/fileinfo)\n[![Build Status](https://travis-ci.org/rafBM/fileinfo.png?branch=master)](https://travis-ci.org/rafBM/fileinfo)\n[![Code Climate](https://codeclimate.com/github/rafBM/fileinfo.png)](https://codeclimate.com/github/rafBM/fileinfo)\n[![Coverage Status](https://coveralls.io/repos/rafBM/fileinfo/badge.png?branch=master)](https://coveralls.io/r/rafBM/fileinfo?branch=master)\n[![Dependency Status](https://gemnasium.com/rafBM/fileinfo.png)](https://gemnasium.com/rafBM/fileinfo)\n\nFileInfo detects file encodings and MIME types using the [wonderful Unix `file` command](http://en.wikipedia.org/wiki/File_\\(command\\)).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'fileinfo'\n```\n\nAnd then execute:\n\n```sh\n$ bundle\n```\n\nOr install it yourself as:\n\n```sh\n$ gem install fileinfo\n```\n\n## Usage\n\n### Detect encoding\n\nUse `FileInfo.parse` with a string or `FileInfo.load` with a filename.\n\n```ruby\nFileInfo.parse('foo bar baz').encoding # =\u003e #\u003cEncoding:US-ASCII\u003e\nFileInfo.parse('föø bår bàz').encoding # =\u003e #\u003cEncoding:UTF-8\u003e\n\nfilename = '/Users/rafbm/Downloads/some_crap_coming_from_windows.csv'\nFileInfo.load(filename).encoding # =\u003e #\u003cEncoding:ISO-8859-1\u003e\n```\n\n### Detect MIME type\n\nA bunch of methods are available depending on your needs.\n\n```ruby\ninfo = FileInfo.load('picture.jpg')\ninfo.type       # =\u003e \"image/jpeg\"\ninfo.media_type # =\u003e \"image\"\ninfo.sub_type   # =\u003e \"jpeg\"\n```\n\nThe `#mime_type` method can also return a `MIME::Type` instance.\n\n```ruby\ninfo = FileInfo.parse('Hello world')\ninfo.mime_type # =\u003e #\u003cMIME::Type:0x007f81a1a36090 @content_type=\"text/plain\" ...\u003e\n```\n\n**NOTE:** You must install the `mime-types` gem yourself as it is not a dependency of `fileinfo`.\n\nFinally, `#content_type` can be used to get the full string returned by `file --mime --brief`.\n\n```ruby\ninfo = FileInfo.parse('Hëllø wõrld')\ninfo.content_type # =\u003e \"text/plain; charset=utf-8\"\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n---\n\n© 2017 [Rafaël Blais Masson](http://rafbm.com). FileInfo is released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafbm%2Ffileinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafbm%2Ffileinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafbm%2Ffileinfo/lists"}