Updated tests. Added a FORMAT flag to make things clearer.

This commit is contained in:
Alan Kligman 2012-10-13 11:06:17 -04:00
parent 4dc7474fd5
commit c434385fe4
2 changed files with 33 additions and 20 deletions

View File

@ -26,24 +26,26 @@ require(["src/filesystem"], function(IDBFS) {
if(!error) { if(!error) {
console.log("bytes written:", bytes_written); console.log("bytes written:", bytes_written);
} }
fd.seek(-bytes_written); fs.dump(document.getElementById("stdout"), function() {
var readBuffer = new Uint8Array(8); var readBuffer = new Uint8Array(8);
fd.read(readBuffer, function(error, bytes_read, buffer) { fd.seek(-bytes_written);
if(!error) { fd.read(readBuffer, function(error, bytes_read, buffer) {
console.log("bytes read:", bytes_read); if(!error) {
console.log("buffer:", buffer); console.log("bytes read:", bytes_read);
} console.log("buffer:", buffer);
fs.close(fd, function(error) { }
fs.unlink("/tmp/0", function(error) { fs.close(fd, function(error) {
fs.dump(document.getElementById("stdout")); fs.unlink("/tmp/0", function(error) {
fs.dump(document.getElementById("stdout"));
});
}); });
}); });
}); }, true);
}); });
}); });
}); });
}, true); }, IDBFS.FORMAT);
}); });
</script> </script>

View File

@ -486,11 +486,13 @@ define(function(require) {
this.api = api; this.api = api;
// DEBUG // DEBUG
function dump(element) { function dump(element, callback, clear) {
element.innerHTML = "Metadata://<br>"; if(clear) {
var transaction = db.transaction([METADATA_STORE_NAME, FILE_STORE_NAME], IDB_RO); element.innerHTML = "";
var metaStore = transaction.objectStore(METADATA_STORE_NAME); }
var fileStore = transaction.objectStore(FILE_STORE_NAME); element.innerHTML += "Metadata://<br>";
var transaction = db.transaction([METADATA_STORE_NAME], IDB_RO);
var metaStore = transaction.objectStore(METADATA_STORE_NAME);
var metaRequest = metaStore.openCursor(); var metaRequest = metaStore.openCursor();
metaRequest.onsuccess = function(e) { metaRequest.onsuccess = function(e) {
var metaCursor = e.target.result; var metaCursor = e.target.result;
@ -499,12 +501,19 @@ define(function(require) {
metaCursor.continue(); metaCursor.continue();
} else { } else {
element.innerHTML += "Files://<br>" element.innerHTML += "Files://<br>"
fileRequest = fileStore.openCursor(); transaction = db.transaction([FILE_STORE_NAME], IDB_RO);
var fileStore = transaction.objectStore(FILE_STORE_NAME);
var fileRequest = fileStore.openCursor();
fileRequest.onsuccess = function(e) { fileRequest.onsuccess = function(e) {
var fileCursor = e.target.result; var fileCursor = e.target.result;
if(fileCursor) { if(fileCursor) {
element.innerHTML += JSON.stringify(fileCursor.key) + "<br>"; element.innerHTML += JSON.stringify(fileCursor.key) + "<br>";
fileCursor.continue(); fileCursor.continue();
} else {
element.innerHTML += "-----------------<br>";
if(callback && "function" === typeof callback) {
callback.call();
}
} }
} }
} }
@ -515,7 +524,7 @@ define(function(require) {
function mount(name, callback, optFormat) { function mount(name, callback, optFormat) {
debug.info("mount -->"); debug.info("mount -->");
optFormat = (undefined === optFormat) ? false : optFormat; optFormat = (IDBFS.FORMAT === optFormat) ? true : false;
var onerror = genericIDBErrorHandler("mount", callback); var onerror = genericIDBErrorHandler("mount", callback);
var openRequest = indexedDB.open(name); var openRequest = indexedDB.open(name);
openRequest.onupgradeneeded = function(e) { openRequest.onupgradeneeded = function(e) {
@ -574,7 +583,9 @@ define(function(require) {
var IDBFS = { var IDBFS = {
mount: mount, mount: mount,
umount: undefined, umount: undefined,
path: path path: path,
FORMAT: "IDBFS_FORMAT"
}; };
return IDBFS; return IDBFS;