datauris 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +12 -12
- data/lib/datauris/version.rb +1 -1
- data/lib/datauris.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a65cebd38591b1ea9416cbb69498707019dd6e422c0aacc72b404f546270da
|
4
|
+
data.tar.gz: 559e1dbe5a26c70a872ca242b0e4c93a06b8883a0dbe080a3cd38f560019390f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b60dd18069dee8bcb18b6fbb834964f4a55423fe595c8a8b3cad3f50219c39283920f2b14a4dedf72870eddc0575b555729e5763b3369e43aac809fb61b26ef0
|
7
|
+
data.tar.gz: 6872aa3cc3aeffeaebf0632e6dbc287dec2e17d7d3151bf4fd52ec22a9b93580db2ed61821145fc61b2522345ddbc6828e27279abf523990bc72c58190339921
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Data URI Helpers
|
2
2
|
|
3
|
-
datauris - helpers to parse (decode) and build (encode) data uris incl. (strict)base64-encoded/decoded images and more
|
3
|
+
datauris - helpers to parse (decode) and build (encode) data uris incl. (strict) base64-encoded/decoded images and more
|
4
4
|
|
5
5
|
* home :: [github.com/s6ruby/rubidity](https://github.com/s6ruby/rubidity)
|
6
6
|
* bugs :: [github.com/s6ruby/rubidity/issues](https://github.com/s6ruby/rubidity/issues)
|
@@ -58,21 +58,21 @@ Let's try and parse the Wikipedia Data URI examples:
|
|
58
58
|
uri = "data:text/vnd-example+xyz;foo=bar;base64,R0lGODdh"
|
59
59
|
DataUri.valid?( uri )
|
60
60
|
#=> true
|
61
|
-
|
62
|
-
#=> "text/vnd-example+xyz;foo=bar"
|
61
|
+
data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
|
62
|
+
#=> "<blob>", "text/vnd-example+xyz;foo=bar"
|
63
63
|
|
64
64
|
uri = "data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678"
|
65
65
|
DataUri.valid?( uri )
|
66
66
|
#=> true
|
67
|
-
|
68
|
-
#=> "text/plain;charset=UTF-8;page=21"
|
67
|
+
data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
|
68
|
+
#=> "the data:1234,5678", "text/plain;charset=UTF-8;page=21"
|
69
69
|
|
70
70
|
|
71
71
|
uri = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/"
|
72
72
|
DataUri.valid?( uri )
|
73
73
|
#=> true
|
74
|
-
|
75
|
-
#=> "
|
74
|
+
data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
|
75
|
+
#=> "<blob>", "image/jpeg"
|
76
76
|
```
|
77
77
|
|
78
78
|
|
@@ -87,7 +87,7 @@ uri = "data:,"
|
|
87
87
|
|
88
88
|
DataUri.valid?( uri )
|
89
89
|
#=> true
|
90
|
-
|
90
|
+
data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
|
91
91
|
#=> "", ""
|
92
92
|
```
|
93
93
|
|
@@ -98,8 +98,8 @@ uri = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHV..."
|
|
98
98
|
|
99
99
|
DataUri.valid?( uri )
|
100
100
|
#=> true
|
101
|
-
|
102
|
-
#=> "
|
101
|
+
data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
|
102
|
+
#=> "<blob>", "image/jpeg"
|
103
103
|
|
104
104
|
## let's save the jpeg image (blob)
|
105
105
|
write_blob( "0.jpeg", data )
|
@@ -117,8 +117,8 @@ uri = "data:image/png;base64,/9j/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAAB..."
|
|
117
117
|
|
118
118
|
DataUri.valid?( uri )
|
119
119
|
#=> true
|
120
|
-
|
121
|
-
#=> "
|
120
|
+
data, mediatype = DataUri.parse( uri ) ## returns 1) data, 2) mediatype (+parameters)
|
121
|
+
#=> "<blob>", "image/png"
|
122
122
|
|
123
123
|
## let's save the png image (blob)
|
124
124
|
write_blob( "15.png", data )
|
data/lib/datauris/version.rb
CHANGED
data/lib/datauris.rb
CHANGED
@@ -58,7 +58,7 @@ module DataUri
|
|
58
58
|
(?<subtype> [\w.+-]+? )
|
59
59
|
)?
|
60
60
|
(?<parameters> (?: ;
|
61
|
-
[\w
|
61
|
+
[\w-]+?
|
62
62
|
=
|
63
63
|
.+?
|
64
64
|
)*
|
@@ -89,7 +89,11 @@ module DataUri
|
|
89
89
|
## todo/double check - use a different URI decoder - why? why not?
|
90
90
|
URI.decode_uri_component(m[:data])
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
|
+
## returns data first!!!
|
94
|
+
## and mediatype second (to follow the order in build)
|
95
|
+
## - also mediatype is optional - arguable more intuitive - yes,no?
|
96
|
+
[data, mediatype]
|
93
97
|
else
|
94
98
|
raise ArgumentError, "invalid datauri - cannot match regex; sorry"
|
95
99
|
end
|
@@ -201,8 +205,8 @@ module DataUri
|
|
201
205
|
## add alias convenience names - why? why not?
|
202
206
|
class << self
|
203
207
|
alias_method :is_valid?, :valid?
|
204
|
-
alias_method :decode, :parse
|
205
|
-
alias_method :encode, :build
|
208
|
+
alias_method :decode, :parse ### add decode - why? why not?
|
209
|
+
alias_method :encode, :build ### add encode - why? why not?
|
206
210
|
end
|
207
211
|
end # module DataUri
|
208
212
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datauris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|