n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.18k stars 187 forks source link

Generate a download from a buffer #150

Closed reviewher closed 2 years ago

reviewher commented 6 years ago

Is there a MIME type for generating a download from a Buffer or string? To compare with another similar service, RunKit can generate a download button if a command returns a Buffer -- try Buffer([0,1,2,3,4]) in RK. Ideally, something like

$$.mime({ "application/octet-stream": Buffer([0,1,2,3,4]) });

would generate a download link.

n-riesco commented 6 years ago

This would work if the frontend you're using can handle "application/octet-stream", but I don't think the Jupyter Notebook does.

As a workaround, you could generate a download link using $$.html and an <a> tag with href set to a dataURL. See an example:

$$.html("<a download href='data:text/plain;charset=utf-8;base64," + new Buffer("Hello World").toString('base64') + "'>Download<a/>");

image