[ 
https://issues.apache.org/jira/browse/CB-2494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Filip Maj updated CB-2494:
--------------------------

          Description: 
I've added some code to write out the LICENSE file from the cordova-mobile-spec 
project to the PERSISTENT + TEMPORARY FileSystem locations, with the intent of 
reading them via the File API and comparing performance vs a similar action 
using XHR.

The following code reports to work well, but I am having trouble locating the 
file on Android File Transfer or ADB shell. Not sure if it works or not? Heh.

The code below should work, just make sure the initial XHR relative URL points 
to the license file in your case properly.

{code}
        // Write the LICENSE file out to PERSISTENT + TEMPORARY locations.
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "../LICENSE", true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status === 0)) 
{
                var APL = xhr.responseText;
                var approx_size = 12000; // 11-12kb
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 
approx_size, function(persistent_fs) {
                    persistent_fs.root.getFile("LICENSE", {create:true, 
exclusive:false}, function(entry) {
                        console.log(JSON.stringify(entry));
                        entry.createWriter(function(writer) {
                            writer.onwriteend = function(evt) {
                                
window.requestFileSystem(LocalFileSystem.TEMPORARY, approx_size, 
function(temp_fs) {
                                    temp_fs.root.getFile("LICENSE", 
{create:true, exclusive:false}, function(t_entry) {
                                        console.log(JSON.stringify(t_entry));
                                        t_entry.createWriter(function(t_writer) 
{
                                            t_writer.onwriteend = function(evt) 
{
                                                alert('done!');
                                            };
                                            t_writer.write(APL);
                                        }, function(e) {
                                            alert('Error creating LICENSE 
FileWriter');
                                        });
                                    }, function(e) {
                                        alert('Error getting LICENSE file 
entry');
                                    });
                                }, function(e) {
                                    alert('Error retrieving persistent FS');
                                });
                            };
                            writer.write(APL);
                        }, function(e) {
                            alert('Error creating LICENSE FileWriter');
                        });
                    }, function(e) {
                        alert('Error getting LICENSE file entry');
                    });
                }, function(e) {
                    alert('Error retrieving persistent FS');
                });
            }
        };
        xhr.send(null);
{code}
          Environment: 
2.5.0rc1
On a Galaxy Nexus running 4.2.2
    Affects Version/s: 2.5.0
    
> Some wonky FileWriting business going on in Android
> ---------------------------------------------------
>
>                 Key: CB-2494
>                 URL: https://issues.apache.org/jira/browse/CB-2494
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.5.0
>         Environment: 2.5.0rc1
> On a Galaxy Nexus running 4.2.2
>            Reporter: Filip Maj
>            Assignee: Joe Bowser
>
> I've added some code to write out the LICENSE file from the 
> cordova-mobile-spec project to the PERSISTENT + TEMPORARY FileSystem 
> locations, with the intent of reading them via the File API and comparing 
> performance vs a similar action using XHR.
> The following code reports to work well, but I am having trouble locating the 
> file on Android File Transfer or ADB shell. Not sure if it works or not? Heh.
> The code below should work, just make sure the initial XHR relative URL 
> points to the license file in your case properly.
> {code}
>         // Write the LICENSE file out to PERSISTENT + TEMPORARY locations.
>         var xhr = new XMLHttpRequest();
>         xhr.open("GET", "../LICENSE", true);
>         xhr.onreadystatechange = function() {
>             if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status === 
> 0)) {
>                 var APL = xhr.responseText;
>                 var approx_size = 12000; // 11-12kb
>                 window.requestFileSystem(LocalFileSystem.PERSISTENT, 
> approx_size, function(persistent_fs) {
>                     persistent_fs.root.getFile("LICENSE", {create:true, 
> exclusive:false}, function(entry) {
>                         console.log(JSON.stringify(entry));
>                         entry.createWriter(function(writer) {
>                             writer.onwriteend = function(evt) {
>                                 
> window.requestFileSystem(LocalFileSystem.TEMPORARY, approx_size, 
> function(temp_fs) {
>                                     temp_fs.root.getFile("LICENSE", 
> {create:true, exclusive:false}, function(t_entry) {
>                                         console.log(JSON.stringify(t_entry));
>                                         
> t_entry.createWriter(function(t_writer) {
>                                             t_writer.onwriteend = 
> function(evt) {
>                                                 alert('done!');
>                                             };
>                                             t_writer.write(APL);
>                                         }, function(e) {
>                                             alert('Error creating LICENSE 
> FileWriter');
>                                         });
>                                     }, function(e) {
>                                         alert('Error getting LICENSE file 
> entry');
>                                     });
>                                 }, function(e) {
>                                     alert('Error retrieving persistent FS');
>                                 });
>                             };
>                             writer.write(APL);
>                         }, function(e) {
>                             alert('Error creating LICENSE FileWriter');
>                         });
>                     }, function(e) {
>                         alert('Error getting LICENSE file entry');
>                     });
>                 }, function(e) {
>                     alert('Error retrieving persistent FS');
>                 });
>             }
>         };
>         xhr.send(null);
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to