• Stars
    star
    10
  • Rank 1,807,489 (Top 36 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MIME Types for Crystal :: A port of the Ruby MIME::Types library

MIME Types for Crystal Build Status GitHub release Crystal Docs

Description

The mime-types library provides a library and registry for information about MIME content type definitions. It can be used to determine defined filename extensions for MIME types, or to use filename extensions to look up the likely MIME type definitions.

About MIME Media Types

MIME content types are used in MIME-compliant communications, as in e-mail or HTTP traffic, to indicate the type of content which is transmitted. The mime-types library provides the ability for detailed information about MIME entities (provided as an enumerable collection of MIME::Type objects) to be determined and used. There are many types defined by RFCs and vendors, so the list is long but by definition incomplete; don't hesitate to add additional type definitions. MIME type definitions found in mime-types are from RFCs, W3C recommendations, the IANA Media Types registry, and user contributions. It conforms to RFCs 2045 and 2231.

Synopsis

MIME types are used in MIME entities, as in email or HTTP traffic. It is useful at times to have information available about MIME types (or, inversely, about files). A MIME::Type stores the known information about one MIME type.

require "mime/types"

plaintext = MIME::Types["text/plain"] # => [ text/plain ]
text = plaintext.first                # => text/plain

puts text.media_type            # => "text"
puts text.sub_type              # => "plain"

puts text.extensions.join(' ')  # => "txt asc c cc h hh cpp hpp dat hlp"
puts text.preferred_extension   # => "txt"
puts text.friendly              # => "Text Document"
puts text.i18n_key              # => "text.plain"

puts text.encoding              # => quoted-printable
puts text.default_encoding      # => quoted-printable
puts text.binary?               # => false
puts text.ascii?                # => true
puts text.obsolete?             # => false
puts text.registered?           # => true
puts text.complete?             # => true

puts text                       # => "text/plain"

puts text == "text/plain"       # => true
puts "text/plain" == text       # => true
puts text == "text/x-plain"     # => false
puts "text/x-plain" == text     # => false

puts MIME::Type.simplified("x-appl/x-zip")  # => "x-appl/x-zip"
puts MIME::Type.i18n_key("x-appl/x-zip")    # => "x-appl.x-zip"

puts text.like?("text/x-plain")                   # => true
puts text.like?(MIME::Type.new("x-text/x-plain")) # => true

puts text.xref_urls
# => [ "http://www.iana.org/go/rfc2046",
#      "http://www.iana.org/go/rfc3676",
#      "http://www.iana.org/go/rfc5147" ]

xtext = MIME::Type.new("x-text/x-plain")
puts xtext.media_type     # => "text"
puts xtext.raw_media_type # => "x-text"
puts xtext.sub_type       # => "plain"
puts xtext.raw_sub_type   # => "x-plain"
puts xtext.complete?      # => false

puts MIME::Types.any? { |type| type.content_type == "text/plain" }  # => true
puts MIME::Types.all?(&.registered?)                                # => false

# Various string representations of MIME types
qcelp = MIME::Types["audio/QCELP"].first  # => audio/QCELP
puts qcelp.content_type                   # => "audio/QCELP"
puts qcelp.simplified                     # => "audio/qcelp"

xwingz = MIME::Types["application/x-Wingz"].first # => application/x-Wingz
puts xwingz.content_type                          # => "application/x-Wingz"
puts xwingz.simplified                            # => "application/x-wingz"

More Repositories

1

odin

A go-lang library to help build self documenting command line applications.
Go
246
star
2

admiral.cr

A robust DSL for writing command line interfaces written in Crystal.
Crystal
134
star
3

terraform-coreos-user-data

CoreOS cloud config generation via Terraform variables
HCL
46
star
4

promise.cr

A Promise Implementation in Crystal
Crystal
32
star
5

git-get

Git clone that clones into a common path
Go
15
star
6

shell-table.cr

Crystal
10
star
7

flatrack

A static site generator with a little sprinkle of ruby magic
Ruby
9
star
8

react-infinite-pane

Responsive infinite scroll pane for React
JavaScript
6
star
9

dotfiles

Jason Waldrip's Dev Environment
Makefile
6
star
10

crystal-sf2017

Crystal
6
star
11

stripe_rails

Ruby
5
star
12

tint

Go
3
star
13

http_cache_handler

Crystal
3
star
14

jasonwaldrip.com

My Little Website
CSS
3
star
15

graphql.cr

An implementation of GraphQL for Crystal
Crystal
3
star
16

of

A simple gem to give you n number of objects.
Ruby
3
star
17

workman

Define and run parallel workers in go
Go
2
star
18

navigable_hash

Ruby
2
star
19

modloc

Find the source location of a given module or class
Ruby
2
star
20

memory_model

A familar model construct that lives only when your app is running (Great for RSpec!)
Ruby
2
star
21

libgraphql-cr

Crystal
2
star
22

delegated_presenter

DelegatedPresenter, More info on rubydoc.info:
Ruby
1
star
23

docker-ruby-app

Shell
1
star
24

docker-mysql

Shell
1
star
25

docker-rails-app

Shell
1
star
26

docker-mariadb

Shell
1
star
27

faxfinder-override

CSS
1
star
28

docker-base

Shell
1
star
29

relay-vote

A voting app in relay.
JavaScript
1
star
30

docker-node

Shell
1
star
31

docker-host

Ruby
1
star
32

jwaldrip.github.com

1
star
33

def_cache

Ruby
1
star
34

docker-rbenv

Shell
1
star
35

node-docker-example

JavaScript
1
star
36

docker-docker

Shell
1
star
37

all_the_badges

Ruby
1
star
38

modernize-hashes

Ruby
1
star
39

carly-paige

JavaScript
1
star
40

docker-railsdev

A feature full rails development environment.
1
star
41

concerned_inheritance

Ruby
1
star
42

git-cleanremote

Clean up your remote repos
Ruby
1
star
43

pollr

Ruby
1
star
44

12f-elasticsearch

12 Factor Configurable Elasticsearch
Makefile
1
star
45

sinful-proxy

A Simple Proxy Written in Sinatra
Ruby
1
star
46

haml-flatrack

Ruby
1
star
47

homebrew-on-tap

Ruby
1
star
48

slim-flatrack

Slim for flatrack
1
star
49

12f-vault

Shell
1
star
50

keep-em-up

Ruby
1
star
51

tar.cr

Tape archives (tar) are a file format for storing a sequence of files that can be read and written in a streaming manner. This package aims to cover most variations of the format, including those produced by GNU and BSD tar tools.
Crystal
1
star