summaryrefslogtreecommitdiff
path: root/plugins/cordova-plugin-file/www/ubuntu
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/cordova-plugin-file/www/ubuntu')
-rw-r--r--plugins/cordova-plugin-file/www/ubuntu/FileSystem.js34
-rw-r--r--plugins/cordova-plugin-file/www/ubuntu/FileWriter.js135
-rw-r--r--plugins/cordova-plugin-file/www/ubuntu/fileSystems-roots.js53
3 files changed, 222 insertions, 0 deletions
diff --git a/plugins/cordova-plugin-file/www/ubuntu/FileSystem.js b/plugins/cordova-plugin-file/www/ubuntu/FileSystem.js
new file mode 100644
index 00000000..c43da824
--- /dev/null
+++ b/plugins/cordova-plugin-file/www/ubuntu/FileSystem.js
@@ -0,0 +1,34 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+FILESYSTEM_PROTOCOL = "cdvfile";
+
+module.exports = {
+ __format__: function(fullPath) {
+ if (this.name === 'content') {
+ return 'content:/' + fullPath;
+ }
+ var path = ('/' + this.name + (fullPath[0] === '/' ? '' : '/') + encodeURI(fullPath)).replace('//','/');
+
+ return FILESYSTEM_PROTOCOL + '://localhost' + path;
+ }
+};
+
diff --git a/plugins/cordova-plugin-file/www/ubuntu/FileWriter.js b/plugins/cordova-plugin-file/www/ubuntu/FileWriter.js
new file mode 100644
index 00000000..a75506b7
--- /dev/null
+++ b/plugins/cordova-plugin-file/www/ubuntu/FileWriter.js
@@ -0,0 +1,135 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var exec = require('cordova/exec'),
+ FileError = require('./FileError'),
+ ProgressEvent = require('./ProgressEvent');
+
+function write(data) {
+ var that=this;
+ var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
+ var isBinary;
+
+ // Check to see if the incoming data is a blob
+ if (data instanceof File || (supportsBinary && data instanceof Blob)) {
+ var fileReader = new FileReader();
+ fileReader.onload = function() {
+ // Call this method again, with the arraybuffer as argument
+ FileWriter.prototype.write.call(that, this.result);
+ };
+ if (supportsBinary) {
+ fileReader.readAsArrayBuffer(data);
+ } else {
+ fileReader.readAsText(data);
+ }
+ return;
+ }
+
+ // Mark data type for safer transport over the binary bridge
+ isBinary = supportsBinary && (data instanceof ArrayBuffer);
+
+ // Throw an exception if we are already writing a file
+ if (this.readyState === FileWriter.WRITING) {
+ throw new FileError(FileError.INVALID_STATE_ERR);
+ }
+
+ // WRITING state
+ this.readyState = FileWriter.WRITING;
+
+ var me = this;
+
+ // If onwritestart callback
+ if (typeof me.onwritestart === "function") {
+ me.onwritestart(new ProgressEvent("writestart", {"target":me}));
+ }
+
+ if (data instanceof ArrayBuffer || data.buffer instanceof ArrayBuffer) {
+ data = new Uint8Array(data);
+ var binary = "";
+ for (var i = 0; i < data.byteLength; i++) {
+ binary += String.fromCharCode(data[i]);
+ }
+ data = binary;
+ }
+
+ var prefix = "file://localhost";
+ var path = this.localURL;
+ if (path.substr(0, prefix.length) == prefix) {
+ path = path.substr(prefix.length);
+ }
+ // Write file
+ exec(
+ // Success callback
+ function(r) {
+ // If DONE (cancelled), then don't do anything
+ if (me.readyState === FileWriter.DONE) {
+ return;
+ }
+
+ // position always increases by bytes written because file would be extended
+ me.position += r;
+ // The length of the file is now where we are done writing.
+
+ me.length = me.position;
+
+ // DONE state
+ me.readyState = FileWriter.DONE;
+
+ // If onwrite callback
+ if (typeof me.onwrite === "function") {
+ me.onwrite(new ProgressEvent("write", {"target":me}));
+ }
+
+ // If onwriteend callback
+ if (typeof me.onwriteend === "function") {
+ me.onwriteend(new ProgressEvent("writeend", {"target":me}));
+ }
+ },
+ // Error callback
+ function(e) {
+ // If DONE (cancelled), then don't do anything
+ if (me.readyState === FileWriter.DONE) {
+ return;
+ }
+
+ // DONE state
+ me.readyState = FileWriter.DONE;
+
+ // Save error
+ me.error = new FileError(e);
+
+ // If onerror callback
+ if (typeof me.onerror === "function") {
+ me.onerror(new ProgressEvent("error", {"target":me}));
+ }
+
+ // If onwriteend callback
+ if (typeof me.onwriteend === "function") {
+ me.onwriteend(new ProgressEvent("writeend", {"target":me}));
+ }
+ }, "File", "write", [path, data, this.position, isBinary]);
+};
+
+module.exports = {
+ write: write
+};
+
+require("cordova/exec/proxy").add("FileWriter", module.exports);
diff --git a/plugins/cordova-plugin-file/www/ubuntu/fileSystems-roots.js b/plugins/cordova-plugin-file/www/ubuntu/fileSystems-roots.js
new file mode 100644
index 00000000..e132a959
--- /dev/null
+++ b/plugins/cordova-plugin-file/www/ubuntu/fileSystems-roots.js
@@ -0,0 +1,53 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var fsMap = null;
+var FileSystem = require('./FileSystem');
+var LocalFileSystem = require('./LocalFileSystem');
+var exec = require('cordova/exec');
+
+var requestFileSystem = function(type, size, successCallback) {
+ var success = function(file_system) {
+ if (file_system) {
+ if (successCallback) {
+ fs = new FileSystem(file_system.name, file_system.root);
+ successCallback(fs);
+ }
+ }
+ };
+ exec(success, null, "File", "requestFileSystem", [type, size]);
+};
+
+require('./fileSystems').getFs = function(name, callback) {
+ if (fsMap) {
+ callback(fsMap[name]);
+ } else {
+ requestFileSystem(LocalFileSystem.PERSISTENT, 1, function(fs) {
+ requestFileSystem(LocalFileSystem.TEMPORARY, 1, function(tmp) {
+ fsMap = {};
+ fsMap[tmp.name] = tmp;
+ fsMap[fs.name] = fs;
+ callback(fsMap[name]);
+ });
+ });
+ }
+};
+