Published
Edited
Oct 15, 2021
2 forks
Importers
18 stars
Insert cell
Insert cell
viewof file = localFileInput({accept: ".db"})
Insert cell
db = file.sqlite()
Insert cell
db.describe()
Insert cell
function localFileInput({
accept, // e.g., ".txt,.md"
value // set the initial value (typically to a FileAttachment)
} = {}) {
return Object.assign(htl.html`<form><input type=file ${{accept}} oninput=${(event) => {
const {currentTarget: input} = event;
const {form, files: [file]} = input;
form.value = new LocalFile(file);
}}>`, {value});
}
Insert cell
class LocalFile extends AbstractFile {
constructor(file) {
super(file.name);
Object.defineProperty(this, "_", {value: file});
Object.defineProperty(this, "_url", {writable: true});
}
async url() {
return this._url || (this._url = URL.createObjectURL(this._));
}
async blob() {
return this._;
}
async stream() {
return this._.stream();
}
}
Insert cell
AbstractFile = FileAttachment("empty@1").constructor.__proto__
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more