data-uri 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in data-uri.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/data-uri.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "data-uri/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "data-uri"
7
+ s.version = DataURI::VERSION
8
+ s.authors = ["kimoto"]
9
+ s.email = ["sub+peerler@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Data URI}
12
+ s.description = %q{Read / Write Data URI}
13
+
14
+ s.rubyforge_project = "data-uri"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
data/examples/test.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+ # Author: kimoto
4
+
5
+ require 'data-uri'
6
+ p encoded = DataURI.encode("this is test", "text/html")
7
+ p DataURI.decode(encoded)
8
+
data/lib/data-uri.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "data-uri/version"
2
+ require 'base64'
3
+
4
+ module DataURI
5
+ def self.encode(data, type="text/plain")
6
+ "data:" + type + ";base64," + Base64.encode64(data).rstrip
7
+ end
8
+
9
+ def self.decode(uri)
10
+ if uri.match(%r{^data:(.*?);(.*?),(.*)$})
11
+ type = $1
12
+ encoder = $2
13
+ data = $3
14
+ if encoder == "base64"
15
+ return Base64.decode64(data)
16
+ end
17
+ end
18
+
19
+ raise "Illegal format error: #{uri.inspect}"
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module DataURI
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data-uri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kimoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Read / Write Data URI
15
+ email:
16
+ - sub+peerler@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - data-uri.gemspec
25
+ - examples/test.rb
26
+ - lib/data-uri.rb
27
+ - lib/data-uri/version.rb
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: data-uri
48
+ rubygems_version: 1.8.11
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Data URI
52
+ test_files: []
53
+ has_rdoc: