eclipsesource / eclipsesource/tabris-js

Support atob and btoa

Open
#899 7 comments 0 reactions 1 assignee Claimed by @ralfstx View on GitHub
bug js
Dominant language
JavaScript
Stars
1.4k
Forks
171
PR merge metrics
No merged PRs in 30d

Description

Hi,
While using the cordova-plugin-file I have found an inconsistency between IOS and Android.
Android reads binary files as array buffer's fine, but IOS does not (I'll then be using JPEGJS to decode it into ImageData and write it to a canvas.. this works ok on Android but I can't read in the binary image data in IOS).

Here's some sample code that works in the scratchpad to illustrate the problem... it extends the file browser to allow reading image (png files as I the demo app has some easy to find png's we can use) and just outputs to the console when it has worked.

``` js

var currentDirectory;

tabris.create("Page", {
title: "Using the Cordova file plugin...",
topLevel: true,
background: "#fff"
}).once("appear", createExample).open();

function createExample(page) {
var rootDirMappings = [
{name: "cordova.file.applicationDirectory", value: cordova.file.applicationDirectory},
{name: "cordova.file.applicationStorageDirectory", value: cordova.file.applicationStorageDirectory}
];

var rootDirPickerLabel = tabris.create("TextView", {
layoutData: {left: 16, top: 8, right: 16},
text: "Cordova Filesystem Entry Point",
textColor: "#000088"
}).appendTo(page);

var rootDirPicker = tabris.create("Picker", {
layoutData: {left: 16, top: [rootDirPickerLabel, 0], height: 48, right: 16},
items: rootDirMappings.map(function(item) {return item.name;}),
selectionIndex: 0
}).appendTo(page);

var urlBar = tabris.create("Composite", {
layoutData: {left: 0, right: 0, top: [rootDirPicker, 0], height: 48},
}).appendTo(page);

var currentDirectoryView = tabris.create("TextInput", {
layoutData: {left: 16, top: 0, right: [0, 80]},
font: "16px",
editable: false,
autoCorrect: false,
text: currentDirectory
}).appendTo(urlBar);

var upButton = tabris.create("Button", {
layoutData: {left: [currentDirectoryView, 16], right: 16, top: 0},
text: "Up",
enabled: false
}).appendTo(urlBar);

var scrollView = tabris.create("ScrollView", {
direction: "vertical",
layoutData: {left: 0, top: [urlBar, 16], right: 0, bottom: 0}
}).appendTo(page);

var success = function(param) {
console.log("using directory:\n" + JSON.stringify(param));
var directoryReader = param.createReader();
console.log("directoryReader:\n" + JSON.stringify(directoryReader));
directoryReader.readEntries(function(result) {
result.forEach(function (entry) {
var row = tabris.create("Composite", {
layoutData: {left: 0, right: 0, top: ["prev()", 1], height: 72},
background: "#ddd"
}).appendTo(scrollView);
var dirEntryView = tabris.create("TextView", {
layoutData: {left: 16, right: 16, centerY: 0},
font: "10px",
text: entry.fullPath,
markupEnabled: true
}).appendTo(row);
if(entry.isDirectory) {
dirEntryView.set("font", "bold 12px");
dirEntryView.set("textColor", "blue");
dirEntryView.on("tap", function() {
console.log("tapped: " + entry.fullPath);
changeDir(entry.nativeURL);
});
}
if(entry.fullPath.indexOf(".png") != -1) {
dirEntryView.set("font", "bold 12px");
dirEntryView.set("textColor", "green");
dirEntryView.on("tap", function() {
console.log("tapped: " + entry.fullPath);
entry.file(function (entry) {
var reader = new FileReader();

reader.onloadend = function (e) {
console.log("file reading ended", this);
console.log(this.result);
//android reaches here and has the binary file data.. IOS does not
};

console.log("file reading about to start", this);

reader.readAsArrayBuffer(entry);
// IOS fails to in here with "can't find variable atob" .. Android works ok

console.log("file reading about to started", this);
}, console.log("erre", entry));

});
}
});
});
};
var error = function(param) {console.log('== error \"' + param + '\"');};

function changeDir(dir) {
currentDirectory = dir;
console.log("====\nCURRENT DIRECTORY:\n" + currentDirectory);
currentDirectoryView.set("text", currentDirectory);
scrollView.children().dispose();
window.resolveLocalFileSystemURL(currentDirectory, success, error);
}

rootDirPicker.on("select", function(picker, selection, options) {
changeDir(rootDirMappings[options.index].value);
});

}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.