09-25-2012 07:05 PM
Wonder if anyone has more insight about this new feature? There is not whole lot of information about Ripple in general and its official site is vastly outdated.
I have been waiting for Ripple to support blackberry.io.file and blackberry.io.dir.
1. It says it supports BB10 Webworks file system APIs, would it also work for Webworks for Tablet too?
2. Where does it read/write to exactly to emulate a device's file system.
My app reads some text files and it would be great if I can test it on Ripple rather than real device everytime.
Thanks in advance.
10-01-2012 03:44 PM
Hello Arnoldc,
HTML5 Filesystem API is supported in Ripple for bo
On the device, Filesystem API will write to a dire
Please note, that Persistent storage requires user
function onInitFs(fs) {
console.log('Opened file system: ' + fs.name);
}
// Persistent storage requires user's permission when using Ripple within Chrome
window.webkitStorageInfo.requestQuota(window.PERSI STENT, 5*1024*1024 /* 5MB */, function(grantedBytes) {
window.webkitRequestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) {
console.log('Error', e);
});
On the device, there is no need to ask for user's
function onInitFs(fs) {
console.log('Opened file system: ' + fs.name);
}
window.webkitRequestFileSystem(window.PERSISTENT, 5*1024*1024 /*5MB*/, onInitFs, errorHandler);
If you need access to shared resources, you will need to implement the following API's in order to get access to non-sandboxed space (Music/Pictures/Documents/etc):
1. blackberry.io.file/blackberry.io.dir on PlayBook/ BlackBerry OS 6.x,7.x.
https://developer.blackberry.com/html5/apis/blackb
2. blackberry.io for BB10
https://developer.blackberry.com/html5/apis/blackb
Please let me know if you have any follow up questions.
10-02-2012 04:19 PM
Thanks anzor_b but this is not really what I am looking for. I want to learn more about how Ripple maps filesytem in emulator. I am using WebWorks File I/O.
For instead,
When I made a call like:
blackberry.io.dir.listFiles(blackberry.io.dir.appD
This works fine in real device but in Ripple, I see it is accessing file:///accounts/1000/appdata/emulatedapp/shared/d
While I am on this subject, I also stumbled on another thread with similar question raised earlier this year?
10-02-2012 05:43 PM - edited 10-02-2012 10:12 PM
Hello arnoldc,
It appears that in the later builds of Google Chrome (I believe 13 and up), the virtual filesystem used by Chrome Extensions such as Ripple is designed to be hidden from the user.
For example, I stored 4 text files using the FileSystem API in Ripple for Chrome, and found them in the following locations (renamed). It is clear that Chrome is using a database to store this information instead of keeping the files in its original form, which makes sense from a security perspective.
c:\Users\username\AppData\Local\Google\Chrome\User Data\Default\File System\001\p (for persistent) \00\00000000 (instead of log.txt)
As a workaround, have one application store the files and test retrieving the files using the application you are working on.
FYI, the virtual filesystem may be accessed in Chrome using the following URLs:
filesystem:http://localhost/persistent/
filesystem:http://localhost/temporary/
You may also use an extension such as HTML5 FileSystem explorer to view/remove the files. (https://chrome.google.com/webstore/detail/nhnjmpbd
Edit: On mac it should be under /Users/USERNAME/Library/Application Support/Google/Chrome/Default/File System
10-03-2012 02:07 PM
Thanks again, anzor_b.
However I think you address about HTML5 Local filesystem, not Blackberry File APIs
I conduct some tests for more observation.
If I created a txt file within the app by calling blackberry.io.file.saveFile, a subsequent call to
blackberry.io.dir.listFiles() will detect this file in the emulator. But I don't see any file created physically in /Users/USERNAME/Library/Application Support/Google/Chrome/Default/File System.
Now if I take out the save function call and re-run the app, the emulator won't detect this file(or any). Apparently, data is not persistent and I suspect the saved file content is only cached in memory good for that session. Look like file system emulation (for Blackberry Filesystem) is not quite there yet....
10-03-2012 04:28 PM
Hello arnoldc,
After further testing it appears that BB10 and PlayBook may behave differently. Using the BB10 simulator and Ripple, I was able to store a file into the Documents folder (within shared folders). Although Ripple appears to store its filesystem under Chrome's temporary storage, I was able to retrieve the file without any issues after restarting Chrome - it appears to remain persistent.
Here's the code I used.
<script type="text/javascript">
window.addEventListener("load", function(e) {
document.addEventListener("webworksready", initApp);
}, false);
function initApp(){
// un-sandbox file system to access shared folder
blackberry.io.sandbox = false;
window.webkitStorageInfo.requestQuota(window.PERSI STENT, 5*1024*1024, function(grantedBytes) {
window.webkitRequestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) {
console.log('Error', e);
});
}
function onInitFs(fs) {
console.log('Opened file system: ' + fs.name);
fs.root.getFile(blackberry.io.sharedFolder + '/Documents/log.txt', {create: true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
var blob = new Blob(['Lorem Ipsum'], {type: 'text/plain'});
fileWriter.write(blob);
}, errorHandler);
}, errorHandler);
}
</script>
The url to Documents folder containing the log.txt file is
Physically, log.txt was stored in
\Users\abashkhaz\AppData\Local\Google\Chrome\User Data\Default\File System\001\t\00\
Since PlayBook does not yet support blackberry.io, I don't think there is a way to store data into persistent memory in Ripple for Chrome yet.
Can you please post your example using blackberry.io.file.saveFile, I will test on my end and get back to you.
10-03-2012 05:10 PM
Hmm, may be it is not supporting playbook OS platform. Just to clarify, I use WebWorks-TabletOS Version 2.0
And here's the code I used.
function onInitFs() {
// file system test in Ripple
var dest = blackberry.io.dir.appDirs.shared.documents.path;
console.log("onInitFs: 1st checking directory="+dest);
var files=blackberry.io.dir.listFiles(dest);
if (files.length==0) {
console.log('onInitFs: no file found, create one');
var text = "HELLO WORLD";
var blob_data = blackberry.utils.stringToBlob(text);
var destFile = dest+"/log.txt";
try {
blackberry.io.file.saveFile(destFile, blob_data);
console.log("onInitFs: Save text file successfully");
var files=blackberry.io.dir.listFiles(dest);
console.log("onInitFs: 2nd checking directory="+dest);
console.log("list files found:"+files.length);
console.log("First file is named="+files[0]);
} catch(e) {
console.log("onInitFs: Fail to save: ", e.message);
}
}
}