Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add data uri support #311

Closed
wants to merge 1 commit into from
Closed

add data uri support #311

wants to merge 1 commit into from

Conversation

caub
Copy link

@caub caub commented Jul 11, 2017

Just proposing this, to behave like browsers fetch which can accept a data uri

not finished, but I don't have precise ideas on how to do

@codecov-io
Copy link

codecov-io commented Jul 11, 2017

Codecov Report

Merging #311 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #311   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           6      6           
  Lines         422    428    +6     
  Branches      133    134    +1     
=====================================
+ Hits          422    428    +6
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7c1ef8...7bafe6b. Read the comment docs.

@caub caub force-pushed the base64 branch 3 times, most recently from d6d5d00 to 1fb8470 Compare July 11, 2017 07:27
@TimothyGu
Copy link
Collaborator

data URLs are a can of worms as they are notoriously underspecified. I would prefer to use an established parser on npm or something instead of rolling our own. https://www.npmjs.com/package/data-uri-to-buffer looks pretty nice.

Besides that, you have to construct a Response object, and return a promise from fetch that will resolve to that.

You also have to pass the type along to the Response object as a Content-Type header per spec.

Handling non-base64 URLs is needed too. See https://tools.ietf.org/html/rfc2397#section-2 on the format for data URLs in general, though data-uri-to-buffer will do this for you.

@TimothyGu
Copy link
Collaborator

Oh, and you need to be careful to wrap all the errors that may occur in the URL-to-data process in a promise instead of throwing synchronously in fetch().

@caub
Copy link
Author

caub commented Jul 11, 2017

Ok, great, thanks, will do, I'll try to behave like spec/browser

@caub caub changed the title [WIP] add base64 support [WIP] add data uri support Jul 11, 2017
@caub caub changed the title [WIP] add data uri support add data uri support Jul 14, 2017
@caub caub force-pushed the base64 branch 2 times, most recently from 866c86f to df64d7e Compare July 15, 2017 06:29
@caub caub force-pushed the base64 branch 3 times, most recently from 21de65a to d97aaa1 Compare July 31, 2017 22:14
@caub
Copy link
Author

caub commented Jul 31, 2017

it's not very beautiful, but is it ok now?

@TimothyGu
Copy link
Collaborator

I'd like to put this on hold because of whatwg/fetch#579.

@TimothyGu
Copy link
Collaborator

Looks like the standard change has landed. @caub, can you update this module to use https://www.npmjs.com/package/data-urls instead?

@TimothyGu TimothyGu added on hold and removed on hold labels Feb 3, 2018
@caub caub force-pushed the base64 branch 3 times, most recently from 7cf057e to c7aeae3 Compare February 4, 2018 00:09
@caub
Copy link
Author

caub commented Feb 4, 2018

@TimothyGu yup, done

@bitinn
Copy link
Collaborator

bitinn commented Feb 4, 2018

Is data-urls now a dependency instead of devDependency?

@caub
Copy link
Author

caub commented Feb 4, 2018

@bitinn done, indeed

@caub
Copy link
Author

caub commented Jun 6, 2018

it fails on node4 because data-urls contains some destructuring https://github.com/jsdom/data-urls/blob/master/lib/parser.js#L3

might add rollup there so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants