Skip to content

Instantly share code, notes, and snippets.

@xsolon
Created May 6, 2020 23:33
Show Gist options
  • Select an option

  • Save xsolon/39579bf1f121e3634847509abbd595f7 to your computer and use it in GitHub Desktop.

Select an option

Save xsolon/39579bf1f121e3634847509abbd595f7 to your computer and use it in GitHub Desktop.
var readDirectory = async () => {
const opts = { type: 'open-directory' };
const handle = await window.chooseFileSystemEntries(opts);
const entries = await handle.getEntries();
window.entries = entries;
for await (const entry of entries) {
const kind = entry.isFile ? 'File' : 'Directory';
console.log(kind, entry.name);
}
};
var getFile = () => {
};
var btn = $('#btnDir');
btn.unbind();
var myglobal: any = window;
btn.click(async () => {
var fileHandle = await window.chooseFileSystemEntries();
myglobal.fileHandle = fileHandle;
fileHandle.getFile().then((buffer) => {
myglobal.buffer = buffer;
buffer.arrayBuffer().then((x) => {
myglobal.arr = x;
loadPic(myglobal.arr);
})
});
});
var loadPic = (x: ArrayBuffer) => {
var blob = new Blob([x]);
var url = window.URL.createObjectURL(blob)
// @ts-ignore
var img: HTMLImageElement= $('#img1')[0];
img.src = url;
}
var loadAudio = (x: ArrayBuffer) => {
//var audio = $('#audio_player')[0];
var blob = new Blob([x]);
var url = window.URL.createObjectURL(blob)
var audio = new Audio();
audio.src = url;
audio.play();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment