Description
Is there any appetite or prior decision for supporting RFC2397?
If it is something worth doing, what do we imagine the API to be like? A new type? Additions to URL and URLComponents APIs?
I imagine there would be a way to create these URLs as well as deconstructing them.
I think the most common occurrence of this in HTML documents, e.g.:
<IMG
SRC="data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH
hhx4dbgYKAAA7"
ALT="Larry">
I can imagine this being something Swift on Server could be interested in when rendering HTML. In my own case, our APIs were returning these data URLs the native client had to show.
I first noticed this while reviewing some manual string processing code from someone on my team to get the data. Accompanying the code was a link to this RFC.
I would think these kinds of URLs could be supported by existing Foundation types:
// create the URL from some data
let dataURL: URL = URL(data: Data(…), encoding: .base64, mimeType: "image/gif")
// deconstructing the URL
let mimeType: String? = dataURL.mimeType
let encoding = dataURL.dataEncoding
let data = dataURL.data
switch encoding {
case .plainText:
doSomethingWithPlainText(data)
case .base64:
doSomethingWithBase64Data(data)
case .none:
print("it was nil")
}