Skip to content

Commit

Permalink
Add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Sep 29, 2023
1 parent 44f8816 commit c906137
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/localforage/file-blob.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/localforage/file-blob.js
cd ..
cd ..
npm run watch
31 changes: 31 additions & 0 deletions examples/localforage/file-blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import localforage from 'localforage';

localforage.getItem('photo').then(function (image) {
if (!image) {
return;
}

console.log('Load from localforage', image)
})

var req = new XMLHttpRequest();
req.addEventListener('readystatechange', function () {
if (req.readyState === 4) { // readyState DONE
localforage.setItem('photo', req.response).then(function (image) {
console.log('Load from request', image)

// This will be a valid blob URI for an <img> tag.
// var blob = new Blob([image]);
// var imageURI = window.URL.createObjectURL(blob);

}).catch(function (err) {
// This code runs if there were any errors
console.log(err);
});
}
});
req.open('GET', 'assets/images/mushroom.png');
req.responseType = 'arraybuffer';
req.send();


0 comments on commit c906137

Please sign in to comment.