├── .editorconfig
├── .gitignore
├── .jshintrc
├── .npmignore
├── Gruntfile.js
├── README.md
├── cordova
├── config.xml
├── hooks
│ └── README.md
├── plugins
│ ├── android.json
│ ├── ios.json
│ └── org.apache.cordova.file
│ │ ├── .fetch.json
│ │ ├── CONTRIBUTING.md
│ │ ├── LICENSE
│ │ ├── NOTICE
│ │ ├── README.md
│ │ ├── RELEASENOTES.md
│ │ ├── doc
│ │ ├── de
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── es
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── fr
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── index.md
│ │ ├── it
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── ja
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── ko
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── pl
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── plugins.md
│ │ ├── ru
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ └── zh
│ │ │ ├── index.md
│ │ │ └── plugins.md
│ │ ├── package.json
│ │ ├── plugin.xml
│ │ ├── src
│ │ ├── android
│ │ │ ├── ContentFilesystem.java
│ │ │ ├── DirectoryManager.java
│ │ │ ├── EncodingException.java
│ │ │ ├── FileExistsException.java
│ │ │ ├── FileHelper.java
│ │ │ ├── FileUtils.java
│ │ │ ├── Filesystem.java
│ │ │ ├── InvalidModificationException.java
│ │ │ ├── LocalFilesystem.java
│ │ │ ├── LocalFilesystemURL.java
│ │ │ ├── NoModificationAllowedException.java
│ │ │ └── TypeMismatchException.java
│ │ ├── blackberry10
│ │ │ └── index.js
│ │ ├── firefoxos
│ │ │ └── FileProxy.js
│ │ ├── ios
│ │ │ ├── CDVAssetLibraryFilesystem.h
│ │ │ ├── CDVAssetLibraryFilesystem.m
│ │ │ ├── CDVFile.h
│ │ │ ├── CDVFile.m
│ │ │ ├── CDVLocalFilesystem.h
│ │ │ └── CDVLocalFilesystem.m
│ │ ├── ubuntu
│ │ │ ├── file.cpp
│ │ │ └── file.h
│ │ ├── windows
│ │ │ └── FileProxy.js
│ │ └── wp
│ │ │ └── File.cs
│ │ ├── tests
│ │ ├── plugin.xml
│ │ └── tests.js
│ │ └── www
│ │ ├── DirectoryEntry.js
│ │ ├── DirectoryReader.js
│ │ ├── Entry.js
│ │ ├── File.js
│ │ ├── FileEntry.js
│ │ ├── FileError.js
│ │ ├── FileReader.js
│ │ ├── FileSystem.js
│ │ ├── FileUploadOptions.js
│ │ ├── FileUploadResult.js
│ │ ├── FileWriter.js
│ │ ├── Flags.js
│ │ ├── LocalFileSystem.js
│ │ ├── Metadata.js
│ │ ├── ProgressEvent.js
│ │ ├── android
│ │ └── FileSystem.js
│ │ ├── blackberry10
│ │ ├── FileProxy.js
│ │ ├── FileSystem.js
│ │ ├── copyTo.js
│ │ ├── createEntryFromNative.js
│ │ ├── getDirectory.js
│ │ ├── getFile.js
│ │ ├── getFileMetadata.js
│ │ ├── getMetadata.js
│ │ ├── getParent.js
│ │ ├── info.js
│ │ ├── moveTo.js
│ │ ├── readAsArrayBuffer.js
│ │ ├── readAsBinaryString.js
│ │ ├── readAsDataURL.js
│ │ ├── readAsText.js
│ │ ├── readEntries.js
│ │ ├── remove.js
│ │ ├── removeRecursively.js
│ │ ├── requestAllFileSystems.js
│ │ ├── requestAnimationFrame.js
│ │ ├── requestFileSystem.js
│ │ ├── resolveLocalFileSystemURI.js
│ │ ├── setMetadata.js
│ │ ├── truncate.js
│ │ └── write.js
│ │ ├── fileSystemPaths.js
│ │ ├── fileSystems-roots.js
│ │ ├── fileSystems.js
│ │ ├── firefoxos
│ │ └── FileSystem.js
│ │ ├── ios
│ │ └── FileSystem.js
│ │ ├── requestFileSystem.js
│ │ ├── resolveLocalFileSystemURI.js
│ │ ├── ubuntu
│ │ ├── FileSystem.js
│ │ ├── FileWriter.js
│ │ └── fileSystems-roots.js
│ │ └── wp
│ │ └── FileUploadOptions.js
└── www
│ ├── chai.js
│ ├── img
│ └── logo.png
│ ├── index.html
│ ├── mocha.css
│ ├── mocha.js
│ └── test
│ ├── async.js
│ ├── fs.js
│ └── tests.js
├── dist
├── fs.js
└── fs.min.js
├── karma.conf.js
├── package.json
└── src
├── api.js
├── fileSystem.js
└── utils.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*.js]
4 | indent_style = space
5 | indent_size = 2
6 | trim_trailing_whitespace = true
7 | insert_final_newline = true
8 |
9 | [*.css]
10 | indent_style = tab
11 | indent_size = 4
12 | trim_trailing_whitespace = true
13 | insert_final_newline = true
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | npm-debug.log
4 | cordova/platforms
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "globals": {
3 | "before": true,
4 | "after": true,
5 | "describe": true,
6 | "it": true,
7 | "beforeEach": true
8 | },
9 | "curly": true,
10 | "camelcase": false,
11 | "evil": false,
12 | "browser": true,
13 | "trailing": true,
14 | "sub": true,
15 | "eqeqeq": false,
16 | "debug": true,
17 | "eqnull": true,
18 | "devel": false,
19 | "smarttabs": false,
20 | "laxbreak": false,
21 | "laxcomma": true,
22 | "jquery": false,
23 | "loopfunc": true,
24 | "indent": 2,
25 | "bitwise": true,
26 | "noarg": true,
27 | "noempty": true,
28 | "nonew": true,
29 | "undef": true,
30 | "boss": true,
31 | "node": true,
32 | "newcap": true,
33 | "quotmark": "single",
34 | "unused": true,
35 | "strict": true,
36 | "maxparams": 5,
37 | "maxdepth": 5,
38 | "maxstatements": 20,
39 | "maxcomplexity": 10
40 | }
41 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | cordova
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function(grunt) {
4 | require('load-grunt-tasks')(grunt);
5 |
6 | // Project configuration.
7 | grunt.initConfig({
8 | pkg: grunt.file.readJSON('package.json'),
9 |
10 | jshint: {
11 | options: {
12 | jshintrc: './.jshintrc'
13 | },
14 | files: {
15 | src: ['./src/*.js', ]
16 | }
17 | },
18 |
19 | karma: {
20 | browsers: {
21 | configFile: 'karma.conf.js'
22 | }
23 | },
24 |
25 | uglify: {
26 | mangle: {
27 | files: {
28 | './dist/fs.min.js': ['./dist/fs.js']
29 | }
30 | }
31 | },
32 |
33 | shell: {
34 | options: {
35 | stderr: true,
36 | stdout: true,
37 | },
38 | linelint: {
39 | command: './node_modules/.bin/linelint ./src/*.js'
40 | }
41 | },
42 |
43 | lintspaces: {
44 | javascript: {
45 | src: [
46 | 'src/*.js'
47 | ],
48 | options: {
49 | newline: true,
50 | trailingspaces: true,
51 | indentation: 'spaces',
52 | spaces: 2,
53 | ignores: ['js-comments']
54 | }
55 | }
56 | },
57 |
58 | browserify: {
59 | test: {
60 | files: {
61 | './cordova/www/test/fs.js': ['./src/api.js'],
62 | },
63 | options: {
64 | browserifyOptions: {
65 | 'standalone': 'fs',
66 | // 'debug': true
67 | }
68 | }
69 | },
70 | dist: {
71 | files: {
72 | './dist/fs.js': ['./src/api.js'],
73 | },
74 | options: {
75 | browserifyOptions: {
76 | 'standalone': 'fs'
77 | }
78 | }
79 | }
80 | },
81 |
82 | cordovacli: {
83 | options: {
84 | path: './cordova/'
85 | },
86 | build_ios: {
87 | options: {
88 | command: 'build',
89 | platforms: ['ios']
90 | }
91 | },
92 | build_android: {
93 | options: {
94 | command: 'build',
95 | platforms: ['android']
96 | }
97 | },
98 | emulate_android: {
99 | options: {
100 | command: 'emulate',
101 | platforms: ['android']
102 | }
103 | },
104 | emulate_ios: {
105 | options: {
106 | command: 'emulate',
107 | platforms: ['ios']
108 | }
109 | }
110 | }
111 | });
112 |
113 | // Code quality
114 | grunt.registerTask('lint', [
115 | 'shell:linelint',
116 | 'jshint',
117 | 'lintspaces:javascript'
118 | ]);
119 |
120 | // Browser tests
121 | grunt.registerTask('test', [
122 | 'lint',
123 | 'browserify:test',
124 | 'karma:browsers'
125 | ]);
126 |
127 | // Cordova application emulation
128 | grunt.registerTask('test-android', [
129 | 'browserify:test',
130 | 'cordovacli:build_android',
131 | 'cordovacli:emulate_android'
132 | ]);
133 |
134 | grunt.registerTask('test-ios', [
135 | 'browserify:test',
136 | 'cordovacli:build_ios',
137 | 'cordovacli:emulate_ios'
138 | ]);
139 |
140 | // Building the library
141 | grunt.registerTask('build', ['lint', 'browserify:dist', 'uglify:mangle']);
142 | };
143 |
--------------------------------------------------------------------------------
/cordova/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | fstest
4 |
5 | A sample Apache Cordova application that responds to the deviceready event.
6 |
7 |
8 | Apache Cordova Team
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/cordova/plugins/android.json:
--------------------------------------------------------------------------------
1 | {
2 | "prepare_queue": {
3 | "installed": [],
4 | "uninstalled": []
5 | },
6 | "config_munge": {
7 | "files": {
8 | "res/xml/config.xml": {
9 | "parents": {
10 | "/*": [
11 | {
12 | "xml": "",
13 | "count": 1
14 | }
15 | ]
16 | }
17 | },
18 | "AndroidManifest.xml": {
19 | "parents": {
20 | "/*": [
21 | {
22 | "xml": "",
23 | "count": 1
24 | }
25 | ]
26 | }
27 | }
28 | },
29 | "res/xml/config.xml": {
30 | "/*": {
31 | "": 0
32 | }
33 | },
34 | "AndroidManifest.xml": {
35 | "/*": {
36 | "": 0
37 | }
38 | }
39 | },
40 | "installed_plugins": {
41 | "org.apache.cordova.file": {
42 | "PACKAGE_NAME": "com.evanshortiss.fstest"
43 | }
44 | },
45 | "dependent_plugins": {}
46 | }
--------------------------------------------------------------------------------
/cordova/plugins/ios.json:
--------------------------------------------------------------------------------
1 | {
2 | "prepare_queue": {
3 | "installed": [],
4 | "uninstalled": []
5 | },
6 | "config_munge": {
7 | "files": {
8 | "framework": {
9 | "parents": {
10 | "AssetsLibrary.framework": [
11 | {
12 | "xml": "false",
13 | "count": 1
14 | }
15 | ],
16 | "MobileCoreServices.framework": [
17 | {
18 | "xml": "false",
19 | "count": 1
20 | }
21 | ]
22 | }
23 | },
24 | "config.xml": {
25 | "parents": {
26 | "/*": [
27 | {
28 | "xml": "",
29 | "count": 1
30 | }
31 | ]
32 | }
33 | }
34 | },
35 | "framework": {
36 | "AssetsLibrary.framework": {
37 | "false": 0
38 | },
39 | "MobileCoreServices.framework": {
40 | "false": 0
41 | }
42 | },
43 | "config.xml": {
44 | "/*": {
45 | "": 0
46 | }
47 | }
48 | },
49 | "installed_plugins": {
50 | "org.apache.cordova.file": {
51 | "PACKAGE_NAME": "com.evanshortiss.fstest"
52 | }
53 | },
54 | "dependent_plugins": {}
55 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/.fetch.json:
--------------------------------------------------------------------------------
1 | {"source":{"type":"registry","id":"org.apache.cordova.file"}}
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
21 |
22 | # Contributing to Apache Cordova
23 |
24 | Anyone can contribute to Cordova. And we need your contributions.
25 |
26 | There are multiple ways to contribute: report bugs, improve the docs, and
27 | contribute code.
28 |
29 | For instructions on this, start with the
30 | [contribution overview](http://cordova.apache.org/#contribute).
31 |
32 | The details are explained there, but the important items are:
33 | - Sign and submit an Apache ICLA (Contributor License Agreement).
34 | - Have a Jira issue open that corresponds to your contribution.
35 | - Run the tests so your patch doesn't break existing functionality.
36 |
37 | We look forward to your contributions!
38 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/NOTICE:
--------------------------------------------------------------------------------
1 | Apache Cordova
2 | Copyright 2012 The Apache Software Foundation
3 |
4 | This product includes software developed at
5 | The Apache Software Foundation (http://www.apache.org/).
6 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/README.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # org.apache.cordova.file
21 |
22 | Plugin documentation: [doc/index.md](doc/index.md)
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/es/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # Notas para los desarrolladores de plugin
21 |
22 | Estas notas están pensadas principalmente para los desarrolladores de Android y el iOS que quieran escribir plugins que interfaz con el sistema de archivos usando el plugin de archivo.
23 |
24 | ## Trabajando con Cordova archivo sistema URLs
25 |
26 | Desde la versión 1.0.0, este plugin utiliza las direcciones URL con un `cdvfile` plan para todas las comunicaciones sobre el puente, en lugar de exponer rutas de sistema de archivo de dispositivo raw a JavaScript.
27 |
28 | En el lado de JavaScript, esto significa que los objetos FileEntry y DirectoryEntry tienen un atributo fullPath que es relativo a la raíz del sistema de archivos HTML. Si JavaScript API del plugin acepta un objeto FileEntry o DirectoryEntry, debe llamar a `.toURL()` en ese objeto antes de pasarla a través del puente a código nativo.
29 |
30 | ### Conversión de cdvfile: / / URL al fileystem caminos
31 |
32 | Plugins que necesita escribir en el sistema de archivos puede querer convertir un archivo recibido sistema URL a una ubicación de archivos reales. Hay varias formas de hacer esto, dependiendo de la plataforma nativa.
33 |
34 | Es importante recordar que no todos `cdvfile://` URLs son asignables a los archivos reales en el dispositivo. Algunas URLs pueden referirse a activos en dispositivos que no están representados por los archivos, o incluso pueden referirse a recursos remotos. Debido a estas posibilidades, plugins siempre debe probar si consiguen un resultado significativo cuando tratando de convertir URLs en trazados.
35 |
36 | #### Android
37 |
38 | En Android, el método más sencillo para convertir un `cdvfile://` URL a una ruta de sistema de archivos es utilizar `org.apache.cordova.CordovaResourceApi` . `CordovaResourceApi`tiene varios métodos que pueden manejar `cdvfile://` URLs:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | También es posible utilizar directamente el archivo plugin:
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | Para convertir de un camino hacia un `cdvfile://` URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | Si tu plugin crea un archivo y desea devolver un objeto FileEntry para ello, utilice el archivo plugin:
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | Cordova en iOS no utiliza el mismo `CordovaResourceApi` concepto como Android. En iOS, utilice el archivo plugin para convertir las direcciones URL y rutas de archivos.
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | Si tu plugin crea un archivo y desea devolver un objeto FileEntry para ello, utilice el archivo plugin:
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### JavaScript
110 |
111 | En JavaScript, para conseguir un `cdvfile://` URL de un objeto FileEntry o DirectoryEntry, simplemente llame a `.toURL()` en él:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | En plugin manipuladores de respuesta, para convertir de una estructura FileEntry devuelta a un objeto real de la entrada, el código del controlador debe importar el archivo plugin y crear un nuevo objeto:
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/it/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # Note per gli sviluppatori di plugin
21 |
22 | Queste note sono principalmente destinate agli sviluppatori di Android e iOS che vogliono scrivere plugin quale interfaccia con il sistema di file utilizzando il File del plugin.
23 |
24 | ## Lavorare con file di Cordova sistema gli URL
25 |
26 | Dalla versione 1.0.0, questo plugin ha utilizzato gli URL con un `cdvfile` regime per tutte le comunicazioni oltre il ponte, piuttosto che esporre i percorsi del dispositivo raw file system a JavaScript.
27 |
28 | Sul lato JavaScript, questo significa che gli oggetti FileEntry e DirectoryEntry hanno un attributo fullPath che è relativo alla directory principale del sistema di file HTML. Se JavaScript API del vostro plugin accetta un oggetto FileEntry o DirectoryEntry, dovrebbe chiamare `.toURL()` su quell'oggetto prima di passarlo attraverso il ponte in codice nativo.
29 |
30 | ### Conversione cdvfile: / / URL per percorsi fileystem
31 |
32 | Plugin che occorre scrivere al filesystem potrebbe voler convertire un URL del sistema file ricevuto in una filesystem effettiva posizione. Ci sono diversi modi di fare questo, a seconda della piattaforma nativa.
33 |
34 | È importante ricordare che non tutti i `cdvfile://` gli URL sono mappabili ai veri file sul dispositivo. Alcuni URL può riferirsi a beni sul dispositivo che non sono rappresentati da file, o possono anche riferirsi a risorse remote. A causa di queste possibilità, plugin dovrebbe sempre verificare se ottengono un risultato espressivo indietro quando si tenta di convertire gli URL in tracciati.
35 |
36 | #### Android
37 |
38 | Su Android, il metodo più semplice per convertire un `cdvfile://` URL a un percorso di file System è quello di utilizzare `org.apache.cordova.CordovaResourceApi` . `CordovaResourceApi`dispone di diversi metodi in grado di gestire `cdvfile://` URL:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | È anche possibile utilizzare direttamente il File del plugin:
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | Per convertire da un percorso a un `cdvfile://` URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | Se il tuo plugin crea un file e si desidera restituire un oggetto FileEntry per esso, utilizzare il File del plugin:
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | Cordova su iOS non utilizza lo stesso `CordovaResourceApi` concetto come Android. Su iOS, è necessario utilizzare il File del plugin per la conversione tra URL e percorsi del file System.
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | Se il tuo plugin crea un file e si desidera restituire un oggetto FileEntry per esso, utilizzare il File del plugin:
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### JavaScript
110 |
111 | In JavaScript, per ottenere un `cdvfile://` URL da un oggetto FileEntry o DirectoryEntry, semplicemente chiamare `.toURL()` su di esso:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | Nei gestori di risposta plugin, per convertire da una struttura FileEntry restituita in un oggetto effettivo della voce, il codice del gestore dovrebbe importare il File del plugin e creare un nuovo oggetto:
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/ja/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # プラグイン開発者のためのノート
21 |
22 | これらのノートは、主に人造人間と iOS 開発者向けファイルのプラグインを使用して、ファイル システムでプラグインのインターフェイスを記述するもの。
23 |
24 | ## コルドバのファイル システムの Url の操作
25 |
26 | バージョン 1.0.0 以降このプラグインが使用した Url とは `cdvfile` raw デバイス ファイル システム パスを JavaScript に公開するのではなく、ブリッジ上のすべての通信方式します。
27 |
28 | JavaScript 側認証と DirectoryEntry オブジェクトの HTML ファイル システムのルートからの相対である fullPath 属性があることを意味します。 呼び出す必要がありますプラグインの JavaScript API は、認証または DirectoryEntry オブジェクトを受け入れる場合 `.toURL()` 、橋を渡ってネイティブ コードに渡す前に、そのオブジェクト。
29 |
30 | ### Cdvfile を変換する://fileystem のパスに Url
31 |
32 | ファイルシステムへの書き込みする必要があるプラグインは実際のファイルシステムの場所に受信ファイル用の URL を変換したい可能性があります。ネイティブのプラットフォームによって、これを行うための複数の方法があります。
33 |
34 | 覚えておくことが重要ですすべてではない `cdvfile://` の Url はデバイス上の実際のファイルをマッピング可能な。 いくつかの Url は、ファイルでは表されないまたはリモートのリソースを参照することができますもをデバイス上の資産を参照できます。 プラグインはこれらの可能性のために彼らの Url パスに変換するしようとしているときに戻って、有意義な結果を得るかどうか常にテスト必要があります。
35 |
36 | #### アンドロイド
37 |
38 | Android 上で変換する最も簡単な方法は `cdvfile://` を使用してファイルシステムのパスに URL が `org.apache.cordova.CordovaResourceApi` 。 `CordovaResourceApi`扱うことができるいくつかの方法があります `cdvfile://` Url:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | また、ファイル プラグインを直接使用することが可能です。
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | パスから変換する、 `cdvfile://` の URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | あなたのプラグインは、ファイルを作成し、認証オブジェクトを返す場合ファイルのプラグインを使用:
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | IOS にコルドバと同じ使用しない `CordovaResourceApi` アンドロイドとして概念。IOS、上ファイル プラグインを使用して Url をファイルシステムのパスに変換する必要があります。
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | あなたのプラグインは、ファイルを作成し、認証オブジェクトを返す場合ファイルのプラグインを使用:
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### Java スクリプトの設定
110 |
111 | Java スクリプトの設定を取得するには `cdvfile://` 認証または DirectoryEntry オブジェクトから URL を単に呼び出す `.toURL()` に:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | プラグインハンドラーの応答で返された FileEntry 構造体の実際のエントリ オブジェクトを変換するハンドラーのコードする必要がありますファイル プラグインをインポートし、新しいオブジェクトを作成します。
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/ko/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # 플러그인 개발자를 위한 노트
21 |
22 | 이 노트는 주로 파일 플러그인을 사용 하 여 파일 시스템 플러그인 인터페이스를 작성 하 고 싶은 안 드 로이드와 iOS 개발자를 위한 것입니다.
23 |
24 | ## 코르 도우 바 파일 시스템 Url 작업
25 |
26 | 버전 1.0.0, 이후이 플러그인과 Url 사용은 `cdvfile` 교량, 모든 통신 체계 보다는 자바 원시 장치 파일 시스템 경로 노출.
27 |
28 | 자바 스크립트 측면에서 즉, FileEntry 및 DirectoryEntry 개체 fullPath 속성을 HTML 파일 시스템의 루트에 상대적입니다. FileEntry 또는 DirectoryEntry 개체를 수락 하는 플러그인의 자바 API를 호출 해야 `.toURL()` 다리에 걸쳐 네이티브 코드에 전달 하기 전에 해당 개체에.
29 |
30 | ### Cdvfile 변환: / / fileystem 경로 Url
31 |
32 | 플러그인 파일 시스템을 작성 하는 실제 파일 시스템 위치에 받은 파일 시스템 URL을 변환 할 수 있습니다. 이렇게, 네이티브 플랫폼에 따라 여러 방법이 있다.
33 |
34 | 기억 하는 것이 중요 하다 모든 `cdvfile://` Url은 장치에 실제 파일을 매핑. 일부 Url 파일에 의해 표현 되지 않는 또는 심지어 원격 리소스를 참조할 수 있는 장치에 자산을 참조할 수 있습니다. 이러한 가능성 때문에 플러그인 경로를 Url을 변환 하려고 할 때 다시 의미 있는 결과 얻을 지 여부를 항상 테스트 해야 합니다.
35 |
36 | #### 안 드 로이드
37 |
38 | 안 드 로이드, 변환 하는 간단한 방법에는 `cdvfile://` URL을 파일 시스템 경로 사용 하는 `org.apache.cordova.CordovaResourceApi` . `CordovaResourceApi`처리할 수 있는 여러 가지 방법에는 `cdvfile://` Url:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | 그것은 또한 파일 플러그인을 직접 사용할 수 있습니다:
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | 경로를 변환 하는 `cdvfile://` URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | 플러그인 파일을 만들고 그것에 대 한 FileEntry 개체를 반환 하려면, 파일 플러그인을 사용.
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | IOS에서 코르도바 같은 사용 하지 않는 `CordovaResourceApi` 안 드 로이드 개념. Ios, Url 및 파일 시스템 경로 사이의 변환할 파일 플러그인을 사용 해야 합니다.
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | 플러그인 파일을 만들고 그것에 대 한 FileEntry 개체를 반환 하려면, 파일 플러그인을 사용.
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### 자바 스크립트
110 |
111 | 자바 스크립트에서는 `cdvfile://` FileEntry 또는 DirectoryEntry 개체에서 URL를 호출 하면 `.toURL()` 그것에:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | 플러그인 응답 처리기에서 반환 된 FileEntry 구조에서 실제 항목 개체 변환 하려면 처리기 코드 해야 파일 플러그인 가져오고 새 개체를 만들:
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/pl/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # Uwagi dla programistów wtyczki
21 |
22 | Te notatki są przeznaczone przede wszystkim dla Androida i iOS programistów, którzy chcieli pisac pluginy które interfejs z systemu plików za pomocą wtyczki pliku.
23 |
24 | ## Praca z Cordova pliku system adresów URL
25 |
26 | Od wersji 1.0.0, ten plugin jest używane adresy URL z `cdvfile` system do komunikacji przez most, a nie narażać urządzenia raw ścieżki systemu plików JavaScript.
27 |
28 | Na stronie JavaScript oznacza to, że FileEntry i DirectoryEntry obiekty mają fullPath atrybut, który jest głównym systemie plików HTML. Jeśli twój plugin JavaScript API akceptuje obiektu DirectoryEntry lub FileEntry, należy zadzwonić `.toURL()` na obiekt przed przekazaniem przez most do kodu macierzystego.
29 |
30 | ### Konwersja cdvfile: / / URL do ścieżki fileystem
31 |
32 | Wtyczek, które trzeba pisać do systemu plików może chcesz przekonwertować odebranych plików systemu adres URL lokalizacji rzeczywistych plików. Istnieje wiele sposobów działania, od macierzystego platformy.
33 |
34 | Ważne jest, aby pamiętać, że nie wszystkie `cdvfile://` adresy URL są można zmapować na prawdziwe akta urządzeniu. Niektóre adresy URL może odnosić się do aktywów na urządzeniu, które nie są reprezentowane przez pliki, lub nawet może odnosić się do zasobów zdalnych. Z powodu tych możliwości wtyczki należy zawsze sprawdzić, czy się znaczących wyników wstecz, podczas próby konwersji adresów URL do ścieżki.
35 |
36 | #### Android
37 |
38 | Na Android, najprostsza metoda konwersji `cdvfile://` URL do ścieżki systemu plików jest użycie `org.apache.cordova.CordovaResourceApi` . `CordovaResourceApi`jest kilka metod, które mogą obsługiwać `cdvfile://` adresów URL:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | Jest również możliwe, aby korzystać z wtyczki pliku bezpośrednio:
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | Do przeliczenia ścieżki do `cdvfile://` adres URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | Jeśli twój plugin tworzy plik, i chcesz zwraca obiekt FileEntry dla niego, użyj pliku plugin:
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | Cordova na iOS nie korzystać z tego samego `CordovaResourceApi` koncepcji jak Android. Na iOS należy użyć pliku plugin do konwersji między adresach URL i ścieżkach plików.
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | Jeśli twój plugin tworzy plik, i chcesz zwraca obiekt FileEntry dla niego, użyj pliku plugin:
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### JavaScript
110 |
111 | W JavaScript, aby uzyskać `cdvfile://` adres URL z obiektu FileEntry lub DirectoryEntry, wystarczy zadzwonić `.toURL()` na to:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | W plugin obsługi odpowiedzi do przeliczenia strukturę FileEntry wrócił do rzeczywistego obiektu wejścia, kod obsługi należy importować pliku plugin i utworzyć nowy obiekt:
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | Notes for plugin developers
21 | ===========================
22 |
23 | These notes are primarily intended for Android and iOS developers who want to write plugins which interface with the file system using the File plugin.
24 |
25 | Working with Cordova file system URLs
26 | -------------------------------------
27 |
28 | Since version 1.0.0, this plugin has used URLs with a `cdvfile` scheme for all communication over the bridge, rather than exposing raw device file system paths to JavaScript.
29 |
30 | On the JavaScript side, this means that FileEntry and DirectoryEntry objects have a fullPath attribute which is relative to the root of the HTML file system. If your plugin's JavaScript API accepts a FileEntry or DirectoryEntry object, you should call `.toURL()` on that object before passing it across the bridge to native code.
31 |
32 | ### Converting cdvfile:// URLs to fileystem paths
33 |
34 | Plugins which need to write to the filesystem may want to convert a received file system URL to an actual filesystem location. There are multiple ways of doing this, depending on the native platform.
35 |
36 | It is important to remember that not all `cdvfile://` URLs are mappable to real files on the device. Some URLs can refer to assets on device which are not represented by files, or can even refer to remote resources. Because of these possibilities, plugins should always test whether they get a meaningful result back when trying to convert URLs to paths.
37 |
38 | #### Android
39 |
40 | On Android, the simplest method to convert a `cdvfile://` URL to a filesystem path is to use `org.apache.cordova.CordovaResourceApi`. `CordovaResourceApi` has several methods which can handle `cdvfile://` URLs:
41 |
42 | // webView is a member of the Plugin class
43 | CordovaResourceApi resourceApi = webView.getResourceApi();
44 |
45 | // Obtain a file:/// URL representing this file on the device,
46 | // or the same URL unchanged if it cannot be mapped to a file
47 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
48 |
49 | It is also possible to use the File plugin directly:
50 |
51 | import org.apache.cordova.file.FileUtils;
52 | import org.apache.cordova.file.FileSystem;
53 | import java.net.MalformedURLException;
54 |
55 | // Get the File plugin from the plugin manager
56 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
57 |
58 | // Given a URL, get a path for it
59 | try {
60 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
61 | } catch (MalformedURLException e) {
62 | // The filesystem url wasn't recognized
63 | }
64 |
65 | To convert from a path to a `cdvfile://` URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 | If your plugin creates a file, and you want to return a FileEntry object for it, use the File plugin:
76 |
77 | // Return a JSON structure suitable for returning to JavaScript,
78 | // or null if this file is not representable as a cdvfile URL.
79 | JSONObject entry = filePlugin.getEntryForFile(file);
80 |
81 | #### iOS
82 |
83 | Cordova on iOS does not use the same `CordovaResourceApi` concept as Android. On iOS, you should use the File plugin to convert between URLs and filesystem paths.
84 |
85 | // Get a CDVFilesystem URL object from a URL string
86 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
87 | // Get a path for the URL object, or nil if it cannot be mapped to a file
88 | NSString* path = [filePlugin filesystemPathForURL:url];
89 |
90 |
91 | // Get a CDVFilesystem URL object for a device path, or
92 | // nil if it cannot be represented as a cdvfile URL.
93 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
94 | // Get the string representation of the URL object
95 | NSString* cdvfileURL = [url absoluteString];
96 |
97 | If your plugin creates a file, and you want to return a FileEntry object for it, use the File plugin:
98 |
99 | // Get a CDVFilesystem URL object for a device path, or
100 | // nil if it cannot be represented as a cdvfile URL.
101 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
102 | // Get a structure to return to JavaScript
103 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
104 |
105 | #### JavaScript
106 |
107 | In JavaScript, to get a `cdvfile://` URL from a FileEntry or DirectoryEntry object, simply call `.toURL()` on it:
108 |
109 | var cdvfileURL = entry.toURL();
110 |
111 | In plugin response handlers, to convert from a returned FileEntry structure to an actual Entry object, your handler code should import the File plugin and create a new object:
112 |
113 | // create appropriate Entry object
114 | var entry;
115 | if (entryStruct.isDirectory) {
116 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
117 | } else {
118 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
119 | }
120 |
121 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/ru/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # Примечания для разработчиков плагинов
21 |
22 | Эти примечания предназначены прежде всего для Android и iOS разработчиков, которые хотят писать плагины какой интерфейс с файловой системой, с помощью файла плагина.
23 |
24 | ## Работа с Кордова файловой системы URL
25 |
26 | Начиная с версии 1.0.0, этот плагин использует URL-адресов с `cdvfile` схема для всех коммуникации через мост, а не подвергая пути файловой системы raw устройства для JavaScript.
27 |
28 | На стороне JavaScript это означает, что объекты DirectoryEntry и FileEntry fullPath атрибут, который является по отношению к корневой файловой системе HTML. Если ваш плагин JavaScript API принимает объект DirectoryEntry или FileEntry, необходимо вызвать `.toURL()` для этого объекта перед передачей их через мост в машинный код.
29 |
30 | ### Преобразование cdvfile: / / URL-адреса в пути fileystem
31 |
32 | Плагины, которые нужно написать в файловой системе может потребоваться преобразовать URL-адреса системы полученный файл в место фактической файловой системы. Существует несколько способов сделать это, в зависимости от родной платформе.
33 |
34 | Важно помнить, что не все `cdvfile://` URL-адреса являются отображаемыми файлами на устройстве. Некоторые URL может относиться к активам на устройстве, которые не представлены файлы, или может даже обратиться к удаленным ресурсам. Из-за эти возможности плагины следует всегда проверять ли они получают результат обратно при попытке преобразовать URL-адреса в пути.
35 |
36 | #### Android
37 |
38 | На Android, самый простой способ для преобразования `cdvfile://` URL-адрес к пути файловой системы заключается в использовании `org.apache.cordova.CordovaResourceApi` . `CordovaResourceApi`Есть несколько методов, которые можно обработать `cdvfile://` URL-адреса:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | Это также можно использовать плагин файл непосредственно:
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | Для преобразования пути к `cdvfile://` URL-адрес:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | Если ваш плагин создает файл, и вы хотите вернуть объект FileEntry для него, используйте файл плагина:
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | Кордова на iOS не использовать те же `CordovaResourceApi` понятие, как Android. На iOS вы должны использовать файл плагин для преобразования URL-адреса и пути файловой системы.
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | Если ваш плагин создает файл, и вы хотите вернуть объект FileEntry для него, используйте файл плагина:
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### JavaScript
110 |
111 | В JavaScript, чтобы получить `cdvfile://` URL от объекта DirectoryEntry или FileEntry, просто позвоните `.toURL()` на него:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | В плагин обработчики ответ для преобразования из возвращаемой структуры FileEntry объект фактического вступления, код обработчика следует импортировать файл плагина и создайте новый объект:
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/doc/zh/plugins.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | # 外掛程式開發人員須知
21 |
22 | 這些筆記主要針對 Android 和 iOS 開發者想要使用的檔案系統使用的檔外掛程式編寫外掛程式哪個介面。
23 |
24 | ## 工作與科爾多瓦檔案系統 Url
25 |
26 | 1.0.0 版以來,這個外掛程式用了 Url 與 `cdvfile` 在橋樑,為所有的通信計畫,而不是暴露 JavaScript 原始設備的檔案系統路徑。
27 |
28 | 在 JavaScript 方面,這意味著 FileEntry 和 DirectoryEntry 的物件具有一個完整路徑屬性是相對於 HTML 檔案系統的根目錄。 如果你的外掛程式的 JavaScript API 接受 FileEntry 或 DirectoryEntry 的物件,則應調用 `.toURL()` 對該物件之前將它在橋上傳遞給本機代碼。
29 |
30 | ### 轉換 cdvfile: / / fileystem 的路徑的 Url
31 |
32 | 需要寫入到檔案系統的外掛程式可能會想要將收到的檔案系統的 URL 轉換為實際的檔案系統位置。有多種方法做這個,根據本機平臺。
33 |
34 | 它是重要的是要記住,不是所有 `cdvfile://` 的 Url 均可映射到設備上的實際檔。 某些 Url 可以引用在設備上不是由檔,或甚至可以引用遠端資源的資產。 由於這些可能性,外掛程式應始終測試是否回試圖將 Url 轉換成路徑時,他們得到有意義的結果。
35 |
36 | #### Android 系統
37 |
38 | 在 android 系統,最簡單的方法來轉換 `cdvfile://` 檔案系統路徑的 URL 是使用 `org.apache.cordova.CordovaResourceApi` 。 `CordovaResourceApi`有幾種方法,可處理 `cdvfile://` 的 Url:
39 |
40 | // webView is a member of the Plugin class
41 | CordovaResourceApi resourceApi = webView.getResourceApi();
42 |
43 | // Obtain a file:/// URL representing this file on the device,
44 | // or the same URL unchanged if it cannot be mapped to a file
45 | Uri fileURL = resourceApi.remapUri(Uri.parse(cdvfileURL));
46 |
47 |
48 | 它也是可以直接使用檔外掛程式:
49 |
50 | import org.apache.cordova.file.FileUtils;
51 | import org.apache.cordova.file.FileSystem;
52 | import java.net.MalformedURLException;
53 |
54 | // Get the File plugin from the plugin manager
55 | FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
56 |
57 | // Given a URL, get a path for it
58 | try {
59 | String path = filePlugin.filesystemPathForURL(cdvfileURL);
60 | } catch (MalformedURLException e) {
61 | // The filesystem url wasn't recognized
62 | }
63 |
64 |
65 | 要轉換的路徑從 `cdvfile://` 的 URL:
66 |
67 | import org.apache.cordova.file.LocalFilesystemURL;
68 |
69 | // Get a LocalFilesystemURL object for a device path,
70 | // or null if it cannot be represented as a cdvfile URL.
71 | LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(path);
72 | // Get the string representation of the URL object
73 | String cdvfileURL = url.toString();
74 |
75 |
76 | 如果你的外掛程式創建一個檔,並且您想要為它返回一個 FileEntry 物件,使用該檔外掛程式:
77 |
78 | // Return a JSON structure suitable for returning to JavaScript,
79 | // or null if this file is not representable as a cdvfile URL.
80 | JSONObject entry = filePlugin.getEntryForFile(file);
81 |
82 |
83 | #### iOS
84 |
85 | 科爾多瓦在 iOS 上的不使用相同 `CordovaResourceApi` 作為 android 系統的概念。在 iOS,應使用檔外掛程式的 Url 和檔案系統路徑之間進行轉換。
86 |
87 | // Get a CDVFilesystem URL object from a URL string
88 | CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithString:cdvfileURL];
89 | // Get a path for the URL object, or nil if it cannot be mapped to a file
90 | NSString* path = [filePlugin filesystemPathForURL:url];
91 |
92 |
93 | // Get a CDVFilesystem URL object for a device path, or
94 | // nil if it cannot be represented as a cdvfile URL.
95 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
96 | // Get the string representation of the URL object
97 | NSString* cdvfileURL = [url absoluteString];
98 |
99 |
100 | 如果你的外掛程式創建一個檔,並且您想要為它返回一個 FileEntry 物件,使用該檔外掛程式:
101 |
102 | // Get a CDVFilesystem URL object for a device path, or
103 | // nil if it cannot be represented as a cdvfile URL.
104 | CDVFilesystemURL* url = [filePlugin fileSystemURLforLocalPath:path];
105 | // Get a structure to return to JavaScript
106 | NSDictionary* entry = [filePlugin makeEntryForLocalURL:url]
107 |
108 |
109 | #### JavaScript
110 |
111 | 在 JavaScript 中,得到 `cdvfile://` URL 從 FileEntry 或 DirectoryEntry 的物件,只需調用 `.toURL()` 對它:
112 |
113 | var cdvfileURL = entry.toURL();
114 |
115 |
116 | 在外掛程式回應處理常式,將從返回的 FileEntry 結構轉換為實際的輸入物件,您的處理常式代碼應該導入的檔外掛程式並創建一個新的物件:
117 |
118 | // create appropriate Entry object
119 | var entry;
120 | if (entryStruct.isDirectory) {
121 | entry = new DirectoryEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
122 | } else {
123 | entry = new FileEntry(entryStruct.name, entryStruct.fullPath, new FileSystem(entryStruct.filesystemName));
124 | }
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/DirectoryManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 | package org.apache.cordova.file;
20 |
21 | import android.os.Environment;
22 | import android.os.StatFs;
23 |
24 | import java.io.File;
25 |
26 | /**
27 | * This class provides file directory utilities.
28 | * All file operations are performed on the SD card.
29 | *
30 | * It is used by the FileUtils class.
31 | */
32 | public class DirectoryManager {
33 |
34 | @SuppressWarnings("unused")
35 | private static final String LOG_TAG = "DirectoryManager";
36 |
37 | /**
38 | * Determine if a file or directory exists.
39 | * @param name The name of the file to check.
40 | * @return T=exists, F=not found
41 | */
42 | public static boolean testFileExists(String name) {
43 | boolean status;
44 |
45 | // If SD card exists
46 | if ((testSaveLocationExists()) && (!name.equals(""))) {
47 | File path = Environment.getExternalStorageDirectory();
48 | File newPath = constructFilePaths(path.toString(), name);
49 | status = newPath.exists();
50 | }
51 | // If no SD card
52 | else {
53 | status = false;
54 | }
55 | return status;
56 | }
57 |
58 | /**
59 | * Get the free disk space
60 | *
61 | * @return Size in KB or -1 if not available
62 | */
63 | public static long getFreeDiskSpace(boolean checkInternal) {
64 | String status = Environment.getExternalStorageState();
65 | long freeSpace = 0;
66 |
67 | // If SD card exists
68 | if (status.equals(Environment.MEDIA_MOUNTED)) {
69 | freeSpace = freeSpaceCalculation(Environment.getExternalStorageDirectory().getPath());
70 | }
71 | else if (checkInternal) {
72 | freeSpace = freeSpaceCalculation("/");
73 | }
74 | // If no SD card and we haven't been asked to check the internal directory then return -1
75 | else {
76 | return -1;
77 | }
78 |
79 | return freeSpace;
80 | }
81 |
82 | /**
83 | * Given a path return the number of free KB
84 | *
85 | * @param path to the file system
86 | * @return free space in KB
87 | */
88 | private static long freeSpaceCalculation(String path) {
89 | StatFs stat = new StatFs(path);
90 | long blockSize = stat.getBlockSize();
91 | long availableBlocks = stat.getAvailableBlocks();
92 | return availableBlocks * blockSize / 1024;
93 | }
94 |
95 | /**
96 | * Determine if SD card exists.
97 | *
98 | * @return T=exists, F=not found
99 | */
100 | public static boolean testSaveLocationExists() {
101 | String sDCardStatus = Environment.getExternalStorageState();
102 | boolean status;
103 |
104 | // If SD card is mounted
105 | if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
106 | status = true;
107 | }
108 |
109 | // If no SD card
110 | else {
111 | status = false;
112 | }
113 | return status;
114 | }
115 |
116 | /**
117 | * Create a new file object from two file paths.
118 | *
119 | * @param file1 Base file path
120 | * @param file2 Remaining file path
121 | * @return File object
122 | */
123 | private static File constructFilePaths (String file1, String file2) {
124 | File newPath;
125 | if (file2.startsWith(file1)) {
126 | newPath = new File(file2);
127 | }
128 | else {
129 | newPath = new File(file1 + "/" + file2);
130 | }
131 | return newPath;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/EncodingException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | package org.apache.cordova.file;
21 |
22 | @SuppressWarnings("serial")
23 | public class EncodingException extends Exception {
24 |
25 | public EncodingException(String message) {
26 | super(message);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/FileExistsException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | package org.apache.cordova.file;
21 |
22 | @SuppressWarnings("serial")
23 | public class FileExistsException extends Exception {
24 |
25 | public FileExistsException(String msg) {
26 | super(msg);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/InvalidModificationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 |
21 | package org.apache.cordova.file;
22 |
23 | @SuppressWarnings("serial")
24 | public class InvalidModificationException extends Exception {
25 |
26 | public InvalidModificationException(String message) {
27 | super(message);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/LocalFilesystemURL.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 | package org.apache.cordova.file;
20 |
21 | import java.util.List;
22 |
23 | import android.net.Uri;
24 |
25 | public class LocalFilesystemURL {
26 |
27 | public static final String FILESYSTEM_PROTOCOL = "cdvfile";
28 |
29 | Uri URL;
30 | String filesystemName;
31 | String fullPath;
32 |
33 | public LocalFilesystemURL(Uri URL) {
34 | this.URL = URL;
35 | this.filesystemName = this.filesystemNameForLocalURL(URL);
36 | this.fullPath = this.fullPathForLocalURL(URL);
37 | }
38 |
39 | private String fullPathForLocalURL(Uri URL) {
40 | if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
41 | String path = URL.getPath();
42 | if (URL.getQuery() != null) {
43 | path = path + "?" + URL.getQuery();
44 | }
45 | return path.substring(path.indexOf('/', 1));
46 | } else if ("content".equals(URL.getScheme())) {
47 | String path = '/' + URL.getHost() + URL.getPath();
48 | // Re-encode path component to handle Android 4.4+ Content URLs
49 | return Uri.encode(path,"/");
50 | }
51 | return null;
52 | }
53 |
54 | private String filesystemNameForLocalURL(Uri URL) {
55 | if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
56 | List pathComponents = URL.getPathSegments();
57 | if (pathComponents != null && pathComponents.size() > 0) {
58 | return pathComponents.get(0);
59 | }
60 | return null;
61 | } else if ("content".equals(URL.getScheme())) {
62 | return "content";
63 | }
64 | return null;
65 | }
66 |
67 | public LocalFilesystemURL(String strURL) {
68 | this(Uri.parse(strURL));
69 | }
70 |
71 | public String toString() {
72 | return "cdvfile://localhost/" + this.filesystemName + this.fullPath;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/NoModificationAllowedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | package org.apache.cordova.file;
21 |
22 | @SuppressWarnings("serial")
23 | public class NoModificationAllowedException extends Exception {
24 |
25 | public NoModificationAllowedException(String message) {
26 | super(message);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/android/TypeMismatchException.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 |
21 | package org.apache.cordova.file;
22 |
23 | @SuppressWarnings("serial")
24 | public class TypeMismatchException extends Exception {
25 |
26 | public TypeMismatchException(String message) {
27 | super(message);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/blackberry10/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 | module.exports = {
22 | setSandbox : function (success, fail, args, env) {
23 | require("lib/webview").setSandbox(JSON.parse(decodeURIComponent(args[0])));
24 | new PluginResult(args, env).ok();
25 | },
26 |
27 | getHomePath: function (success, fail, args, env) {
28 | var homeDir = window.qnx.webplatform.getApplication().getEnv("HOME");
29 | new PluginResult(args, env).ok(homeDir);
30 | },
31 |
32 | requestAllPaths: function (success, fail, args, env) {
33 | var homeDir = 'file://' + window.qnx.webplatform.getApplication().getEnv("HOME").replace('/data', ''),
34 | paths = {
35 | applicationDirectory: homeDir + '/app/native/',
36 | applicationStorageDirectory: homeDir + '/',
37 | dataDirectory: homeDir + '/data/webviews/webfs/persistent/local__0/',
38 | cacheDirectory: homeDir + '/data/webviews/webfs/temporary/local__0/',
39 | externalRootDirectory: 'file:///accounts/1000/removable/sdcard/',
40 | sharedDirectory: homeDir + '/shared/'
41 | };
42 | success(paths);
43 | }
44 | };
45 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/ios/CDVAssetLibraryFilesystem.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVFile.h"
21 |
22 | extern NSString* const kCDVAssetsLibraryPrefix;
23 | extern NSString* const kCDVAssetsLibraryScheme;
24 |
25 | @interface CDVAssetLibraryFilesystem : NSObject {
26 | }
27 |
28 | - (id) initWithName:(NSString *)name;
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/ios/CDVLocalFilesystem.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import "CDVFile.h"
21 |
22 | @interface CDVLocalFilesystem : NSObject {
23 | NSString *_name;
24 | NSString *_fsRoot;
25 | }
26 |
27 | - (id) initWithName:(NSString *)name root:(NSString *)fsRoot;
28 | + (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
29 |
30 | @property (nonatomic,strong) NSString *fsRoot;
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/src/ubuntu/file.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | #ifndef FILEAPI_H_SDASDASDAS
16 | #define FILEAPI_H_SDASDASDAS
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 |
24 | class File: public CPlugin {
25 | Q_OBJECT
26 | public:
27 | explicit File(Cordova *cordova);
28 |
29 | virtual const QString fullName() override {
30 | return File::fullID();
31 | }
32 |
33 | virtual const QString shortName() override {
34 | return "File";
35 | }
36 |
37 | static const QString fullID() {
38 | return "File";
39 | }
40 | QPair resolveURI(const QString &uri);
41 | QPair resolveURI(int ecId, const QString &uri);
42 | QVariantMap file2map(const QFileInfo &dir);
43 |
44 | public slots:
45 | void requestFileSystem(int scId, int ecId, unsigned short type, unsigned long long size);
46 | void resolveLocalFileSystemURI(int scId, int ecId, const QString&);
47 | void getDirectory(int scId, int ecId, const QString&, const QString&, const QVariantMap&);
48 | void getFile(int scId, int ecId, const QString &parentPath, const QString &rpath, const QVariantMap &options);
49 | void readEntries(int scId, int ecId, const QString &uri);
50 | void getParent(int scId, int ecId, const QString &uri);
51 | void copyTo(int scId, int ecId, const QString& source, const QString& destinationDir, const QString& newName);
52 | void moveTo(int scId, int ecId, const QString& source, const QString& destinationDir, const QString& newName);
53 | void getFileMetadata(int scId, int ecId, const QString &);
54 | void getMetadata(int scId, int ecId, const QString &);
55 | void remove(int scId, int ecId, const QString &);
56 | void removeRecursively(int scId, int ecId, const QString&);
57 | void write(int scId, int ecId, const QString&, const QString&, unsigned long long position, bool binary);
58 | void readAsText(int scId, int ecId, const QString&, const QString &encoding, int sliceStart, int sliceEnd);
59 | void readAsDataURL(int scId, int ecId, const QString&, int sliceStart, int sliceEnd);
60 | void readAsArrayBuffer(int scId, int ecId, const QString&, int sliceStart, int sliceEnd);
61 | void readAsBinaryString(int scId, int ecId, const QString&, int sliceStart, int sliceEnd);
62 | void truncate(int scId, int ecId, const QString&, unsigned long long size);
63 |
64 | void _getLocalFilesystemPath(int scId, int ecId, const QString&);
65 | private:
66 | void moveFile(int scId, int ecId,const QString&, const QString&, const QString&);
67 | void moveDir(int scId, int ecId,const QString&, const QString&, const QString&);
68 | bool copyFile(int scId, int ecId, const QString&, const QString&, const QString&);
69 | void copyDir(int scId, int ecId, const QString&, const QString&, const QString&);
70 | bool rmDir(const QDir &dir);
71 | bool copyFolder(const QString&, const QString&);
72 |
73 | QPair GetRelativePath(const QFileInfo &fileInfo);
74 | QVariantMap dir2map(const QDir &dir);
75 |
76 | QMimeDatabase _db;
77 | const QDir _persistentDir;
78 | QNetworkAccessManager _manager;
79 | };
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/tests/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
26 |
27 | Cordova File Plugin Tests
28 | Apache 2.0
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/DirectoryEntry.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var argscheck = require('cordova/argscheck'),
23 | utils = require('cordova/utils'),
24 | exec = require('cordova/exec'),
25 | Entry = require('./Entry'),
26 | FileError = require('./FileError'),
27 | DirectoryReader = require('./DirectoryReader');
28 |
29 | /**
30 | * An interface representing a directory on the file system.
31 | *
32 | * {boolean} isFile always false (readonly)
33 | * {boolean} isDirectory always true (readonly)
34 | * {DOMString} name of the directory, excluding the path leading to it (readonly)
35 | * {DOMString} fullPath the absolute full path to the directory (readonly)
36 | * {FileSystem} filesystem on which the directory resides (readonly)
37 | */
38 | var DirectoryEntry = function(name, fullPath, fileSystem, nativeURL) {
39 |
40 | // add trailing slash if it is missing
41 | if ((fullPath) && !/\/$/.test(fullPath)) {
42 | fullPath += "/";
43 | }
44 | // add trailing slash if it is missing
45 | if (nativeURL && !/\/$/.test(nativeURL)) {
46 | nativeURL += "/";
47 | }
48 | DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL);
49 | };
50 |
51 | utils.extend(DirectoryEntry, Entry);
52 |
53 | /**
54 | * Creates a new DirectoryReader to read entries from this directory
55 | */
56 | DirectoryEntry.prototype.createReader = function() {
57 | return new DirectoryReader(this.toInternalURL());
58 | };
59 |
60 | /**
61 | * Creates or looks up a directory
62 | *
63 | * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory
64 | * @param {Flags} options to create or exclusively create the directory
65 | * @param {Function} successCallback is called with the new entry
66 | * @param {Function} errorCallback is called with a FileError
67 | */
68 | DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
69 | argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments);
70 | var fs = this.filesystem;
71 | var win = successCallback && function(result) {
72 | var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
73 | successCallback(entry);
74 | };
75 | var fail = errorCallback && function(code) {
76 | errorCallback(new FileError(code));
77 | };
78 | exec(win, fail, "File", "getDirectory", [this.toInternalURL(), path, options]);
79 | };
80 |
81 | /**
82 | * Deletes a directory and all of it's contents
83 | *
84 | * @param {Function} successCallback is called with no parameters
85 | * @param {Function} errorCallback is called with a FileError
86 | */
87 | DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
88 | argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments);
89 | var fail = errorCallback && function(code) {
90 | errorCallback(new FileError(code));
91 | };
92 | exec(successCallback, fail, "File", "removeRecursively", [this.toInternalURL()]);
93 | };
94 |
95 | /**
96 | * Creates or looks up a file
97 | *
98 | * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file
99 | * @param {Flags} options to create or exclusively create the file
100 | * @param {Function} successCallback is called with the new entry
101 | * @param {Function} errorCallback is called with a FileError
102 | */
103 | DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
104 | argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments);
105 | var fs = this.filesystem;
106 | var win = successCallback && function(result) {
107 | var FileEntry = require('./FileEntry');
108 | var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL);
109 | successCallback(entry);
110 | };
111 | var fail = errorCallback && function(code) {
112 | errorCallback(new FileError(code));
113 | };
114 | exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]);
115 | };
116 |
117 | module.exports = DirectoryEntry;
118 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/DirectoryReader.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var exec = require('cordova/exec'),
23 | FileError = require('./FileError') ;
24 |
25 | /**
26 | * An interface that lists the files and directories in a directory.
27 | */
28 | function DirectoryReader(localURL) {
29 | this.localURL = localURL || null;
30 | this.hasReadEntries = false;
31 | }
32 |
33 | /**
34 | * Returns a list of entries from a directory.
35 | *
36 | * @param {Function} successCallback is called with a list of entries
37 | * @param {Function} errorCallback is called with a FileError
38 | */
39 | DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
40 | // If we've already read and passed on this directory's entries, return an empty list.
41 | if (this.hasReadEntries) {
42 | successCallback([]);
43 | return;
44 | }
45 | var reader = this;
46 | var win = typeof successCallback !== 'function' ? null : function(result) {
47 | var retVal = [];
48 | for (var i=0; i= 2) {
65 | if (end < 0) {
66 | newEnd = Math.max(size + end, 0);
67 | } else {
68 | newEnd = Math.min(end, size);
69 | }
70 | }
71 |
72 | var newFile = new File(this.name, this.localURL, this.type, this.lastModified, this.size);
73 | newFile.start = this.start + newStart;
74 | newFile.end = this.start + newEnd;
75 | return newFile;
76 | };
77 |
78 |
79 | module.exports = File;
80 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/FileEntry.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var utils = require('cordova/utils'),
23 | exec = require('cordova/exec'),
24 | Entry = require('./Entry'),
25 | FileWriter = require('./FileWriter'),
26 | File = require('./File'),
27 | FileError = require('./FileError');
28 |
29 | /**
30 | * An interface representing a file on the file system.
31 | *
32 | * {boolean} isFile always true (readonly)
33 | * {boolean} isDirectory always false (readonly)
34 | * {DOMString} name of the file, excluding the path leading to it (readonly)
35 | * {DOMString} fullPath the absolute full path to the file (readonly)
36 | * {FileSystem} filesystem on which the file resides (readonly)
37 | */
38 | var FileEntry = function(name, fullPath, fileSystem, nativeURL) {
39 | FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
40 | };
41 |
42 | utils.extend(FileEntry, Entry);
43 |
44 | /**
45 | * Creates a new FileWriter associated with the file that this FileEntry represents.
46 | *
47 | * @param {Function} successCallback is called with the new FileWriter
48 | * @param {Function} errorCallback is called with a FileError
49 | */
50 | FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
51 | this.file(function(filePointer) {
52 | var writer = new FileWriter(filePointer);
53 |
54 | if (writer.localURL === null || writer.localURL === "") {
55 | errorCallback && errorCallback(new FileError(FileError.INVALID_STATE_ERR));
56 | } else {
57 | successCallback && successCallback(writer);
58 | }
59 | }, errorCallback);
60 | };
61 |
62 | /**
63 | * Returns a File that represents the current state of the file that this FileEntry represents.
64 | *
65 | * @param {Function} successCallback is called with the new File object
66 | * @param {Function} errorCallback is called with a FileError
67 | */
68 | FileEntry.prototype.file = function(successCallback, errorCallback) {
69 | var localURL = this.toInternalURL();
70 | var win = successCallback && function(f) {
71 | var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
72 | successCallback(file);
73 | };
74 | var fail = errorCallback && function(code) {
75 | errorCallback(new FileError(code));
76 | };
77 | exec(win, fail, "File", "getFileMetadata", [localURL]);
78 | };
79 |
80 |
81 | module.exports = FileEntry;
82 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/FileError.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * FileError
24 | */
25 | function FileError(error) {
26 | this.code = error || null;
27 | }
28 |
29 | // File error codes
30 | // Found in DOMException
31 | FileError.NOT_FOUND_ERR = 1;
32 | FileError.SECURITY_ERR = 2;
33 | FileError.ABORT_ERR = 3;
34 |
35 | // Added by File API specification
36 | FileError.NOT_READABLE_ERR = 4;
37 | FileError.ENCODING_ERR = 5;
38 | FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
39 | FileError.INVALID_STATE_ERR = 7;
40 | FileError.SYNTAX_ERR = 8;
41 | FileError.INVALID_MODIFICATION_ERR = 9;
42 | FileError.QUOTA_EXCEEDED_ERR = 10;
43 | FileError.TYPE_MISMATCH_ERR = 11;
44 | FileError.PATH_EXISTS_ERR = 12;
45 |
46 | module.exports = FileError;
47 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/FileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var DirectoryEntry = require('./DirectoryEntry');
23 |
24 | /**
25 | * An interface representing a file system
26 | *
27 | * @constructor
28 | * {DOMString} name the unique name of the file system (readonly)
29 | * {DirectoryEntry} root directory of the file system (readonly)
30 | */
31 | var FileSystem = function(name, root) {
32 | this.name = name;
33 | if (root) {
34 | this.root = new DirectoryEntry(root.name, root.fullPath, this, root.nativeURL);
35 | } else {
36 | this.root = new DirectoryEntry(this.name, '/', this);
37 | }
38 | };
39 |
40 | FileSystem.prototype.__format__ = function(fullPath) {
41 | return fullPath;
42 | };
43 |
44 | FileSystem.prototype.toJSON = function() {
45 | return "";
46 | };
47 |
48 | module.exports = FileSystem;
49 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/FileUploadOptions.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * Options to customize the HTTP request used to upload files.
24 | * @constructor
25 | * @param fileKey {String} Name of file request parameter.
26 | * @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
27 | * @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
28 | * @param params {Object} Object with key: value params to send to the server.
29 | * @param headers {Object} Keys are header names, values are header values. Multiple
30 | * headers of the same name are not supported.
31 | */
32 | var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers, httpMethod) {
33 | this.fileKey = fileKey || null;
34 | this.fileName = fileName || null;
35 | this.mimeType = mimeType || null;
36 | this.params = params || null;
37 | this.headers = headers || null;
38 | this.httpMethod = httpMethod || null;
39 | };
40 |
41 | module.exports = FileUploadOptions;
42 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/FileUploadResult.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * FileUploadResult
24 | * @constructor
25 | */
26 | module.exports = function FileUploadResult(size, code, content) {
27 | this.bytesSent = size;
28 | this.responseCode = code;
29 | this.response = content;
30 | };
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/Flags.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * Supplies arguments to methods that lookup or create files and directories.
24 | *
25 | * @param create
26 | * {boolean} file or directory if it doesn't exist
27 | * @param exclusive
28 | * {boolean} used with create; if true the command will fail if
29 | * target path exists
30 | */
31 | function Flags(create, exclusive) {
32 | this.create = create || false;
33 | this.exclusive = exclusive || false;
34 | }
35 |
36 | module.exports = Flags;
37 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/LocalFileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | exports.TEMPORARY = 0;
23 | exports.PERSISTENT = 1;
24 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/Metadata.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * Information about the state of the file or directory
24 | *
25 | * {Date} modificationTime (readonly)
26 | */
27 | var Metadata = function(metadata) {
28 | if (typeof metadata == "object") {
29 | this.modificationTime = new Date(metadata.modificationTime);
30 | this.size = metadata.size || 0;
31 | } else if (typeof metadata == "undefined") {
32 | this.modificationTime = null;
33 | this.size = 0;
34 | } else {
35 | /* Backwards compatiblity with platforms that only return a timestamp */
36 | this.modificationTime = new Date(metadata);
37 | }
38 | };
39 |
40 | module.exports = Metadata;
41 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/ProgressEvent.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | // If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
23 | // Feature test: See if we can instantiate a native ProgressEvent;
24 | // if so, use that approach,
25 | // otherwise fill-in with our own implementation.
26 | //
27 | // NOTE: right now we always fill in with our own. Down the road would be nice if we can use whatever is native in the webview.
28 | var ProgressEvent = (function() {
29 | /*
30 | var createEvent = function(data) {
31 | var event = document.createEvent('Events');
32 | event.initEvent('ProgressEvent', false, false);
33 | if (data) {
34 | for (var i in data) {
35 | if (data.hasOwnProperty(i)) {
36 | event[i] = data[i];
37 | }
38 | }
39 | if (data.target) {
40 | // TODO: cannot call .dispatchEvent
41 | // need to first figure out how to implement EventTarget
42 | }
43 | }
44 | return event;
45 | };
46 | try {
47 | var ev = createEvent({type:"abort",target:document});
48 | return function ProgressEvent(type, data) {
49 | data.type = type;
50 | return createEvent(data);
51 | };
52 | } catch(e){
53 | */
54 | return function ProgressEvent(type, dict) {
55 | this.type = type;
56 | this.bubbles = false;
57 | this.cancelBubble = false;
58 | this.cancelable = false;
59 | this.lengthComputable = false;
60 | this.loaded = dict && dict.loaded ? dict.loaded : 0;
61 | this.total = dict && dict.total ? dict.total : 0;
62 | this.target = dict && dict.target ? dict.target : null;
63 | };
64 | //}
65 | })();
66 |
67 | module.exports = ProgressEvent;
68 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/android/FileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | FILESYSTEM_PROTOCOL = "cdvfile";
23 |
24 | module.exports = {
25 | __format__: function(fullPath) {
26 | if (this.name === 'content') {
27 | return 'content:/' + fullPath;
28 | }
29 | var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
30 | return FILESYSTEM_PROTOCOL + '://localhost' + path;
31 | }
32 | };
33 |
34 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/FileProxy.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * FileProxy
24 | *
25 | * Register all File exec calls to be handled by proxy
26 | */
27 |
28 | module.exports = {
29 | copyTo: require('org.apache.cordova.file.copyToProxy'),
30 | getDirectory: require('org.apache.cordova.file.getDirectoryProxy'),
31 | getFile: require('org.apache.cordova.file.getFileProxy'),
32 | getFileMetadata: require('org.apache.cordova.file.getFileMetadataProxy'),
33 | getMetadata: require('org.apache.cordova.file.getMetadataProxy'),
34 | getParent: require('org.apache.cordova.file.getParentProxy'),
35 | moveTo: require('org.apache.cordova.file.moveToProxy'),
36 | readAsArrayBuffer: require('org.apache.cordova.file.readAsArrayBufferProxy'),
37 | readAsBinaryString: require('org.apache.cordova.file.readAsBinaryStringProxy'),
38 | readAsDataURL: require('org.apache.cordova.file.readAsDataURLProxy'),
39 | readAsText: require('org.apache.cordova.file.readAsTextProxy'),
40 | readEntries: require('org.apache.cordova.file.readEntriesProxy'),
41 | remove: require('org.apache.cordova.file.removeProxy'),
42 | removeRecursively: require('org.apache.cordova.file.removeRecursivelyProxy'),
43 | resolveLocalFileSystemURI: require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
44 | requestAllFileSystems: require('org.apache.cordova.file.requestAllFileSystemsProxy'),
45 | requestFileSystem: require('org.apache.cordova.file.requestFileSystemProxy'),
46 | setMetadata: require('org.apache.cordova.file.setMetadataProxy'),
47 | truncate: require('org.apache.cordova.file.truncateProxy'),
48 | write: require('org.apache.cordova.file.writeProxy')
49 | };
50 |
51 | require('cordova/exec/proxy').add('File', module.exports);
52 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/FileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * FileSystem
24 | *
25 | * Translate temporary / persistent / root file paths
26 | */
27 |
28 | var info = require("org.apache.cordova.file.bb10FileSystemInfo");
29 |
30 | module.exports = {
31 | __format__: function(fullPath) {
32 | switch (this.name) {
33 | case 'temporary':
34 | path = info.temporaryPath + fullPath;
35 | break;
36 | case 'persistent':
37 | path = info.persistentPath + fullPath;
38 | break;
39 | case 'root':
40 | path = 'file://' + fullPath;
41 | break;
42 | }
43 | return window.encodeURI(path);
44 | }
45 | };
46 |
47 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/copyTo.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * copyTo
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of entry to copy
28 | * 1 - URL of the directory into which to copy/move the entry
29 | * 2 - the new name of the entry, defaults to the current name
30 | * move - if true, delete the entry which was copied
31 | * OUT:
32 | * success - entry for the copied file or directory
33 | * fail - FileError
34 | */
35 |
36 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
37 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
38 |
39 | module.exports = function (success, fail, args, move) {
40 | var uri = args[0],
41 | destination = args[1],
42 | fileName = args[2],
43 | copiedEntry,
44 | onSuccess = function () {
45 | resolve(
46 | function (entry) {
47 | if (typeof(success) === 'function') {
48 | success(entry);
49 | }
50 | },
51 | onFail,
52 | [destination + copiedEntry.name]
53 | );
54 | },
55 | onFail = function (error) {
56 | if (typeof(fail) === 'function') {
57 | if (error && error.code) {
58 | //set error codes expected by mobile spec
59 | if (uri === destination) {
60 | fail(FileError.INVALID_MODIFICATION_ERR);
61 | } else if (error.code === FileError.SECURITY_ERR) {
62 | fail(FileError.INVALID_MODIFICATION_ERR);
63 | } else {
64 | fail(error.code);
65 | }
66 | } else {
67 | fail(error);
68 | }
69 | }
70 | },
71 | writeFile = function (fileEntry, blob, entry) {
72 | copiedEntry = fileEntry;
73 | fileEntry.createWriter(function (fileWriter) {
74 | fileWriter.onwriteend = function () {
75 | if (move) {
76 | entry.nativeEntry.remove(onSuccess, function () {
77 | console.error("Move operation failed. Files may exist at both source and destination");
78 | });
79 | } else {
80 | onSuccess();
81 | }
82 | };
83 | fileWriter.onerror = onFail;
84 | fileWriter.write(blob);
85 | }, onFail);
86 | },
87 | copyFile = function (entry) {
88 | if (entry.nativeEntry.file) {
89 | entry.nativeEntry.file(function (file) {
90 | var reader = new FileReader()._realReader;
91 | reader.onloadend = function (e) {
92 | var contents = new Uint8Array(this.result),
93 | blob = new Blob([contents]);
94 | resolve(function (destEntry) {
95 | requestAnimationFrame(function () {
96 | destEntry.nativeEntry.getFile(fileName, {create: true}, function (fileEntry) {
97 | writeFile(fileEntry, blob, entry);
98 | }, onFail);
99 | });
100 | }, onFail, [destination]);
101 | };
102 | reader.onerror = onFail;
103 | reader.readAsArrayBuffer(file);
104 | }, onFail);
105 | } else {
106 | onFail(FileError.INVALID_MODIFICATION_ERR);
107 | }
108 | },
109 | copyDirectory = function (entry) {
110 | resolve(function (destEntry) {
111 | if (entry.filesystemName !== destEntry.filesystemName) {
112 | console.error("Copying directories between filesystems is not supported on BB10");
113 | onFail(FileError.INVALID_MODIFICATION_ERR);
114 | } else {
115 | entry.nativeEntry.copyTo(destEntry.nativeEntry, fileName, function () {
116 | resolve(function (copiedDir) {
117 | copiedEntry = copiedDir;
118 | if (move) {
119 | entry.nativeEntry.removeRecursively(onSuccess, onFail);
120 | } else {
121 | onSuccess();
122 | }
123 | }, onFail, [destination + fileName]);
124 | }, onFail);
125 | }
126 | }, onFail, [destination]);
127 | };
128 | if (destination + fileName === uri) {
129 | onFail(FileError.INVALID_MODIFICATION_ERR);
130 | } else if (fileName.indexOf(':') > -1) {
131 | onFail(FileError.ENCODING_ERR);
132 | } else {
133 | resolve(function (entry) {
134 | if (entry.isDirectory) {
135 | copyDirectory(entry);
136 | } else {
137 | copyFile(entry);
138 | }
139 | }, onFail, [uri]);
140 | }
141 | };
142 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/createEntryFromNative.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * createEntryFromNative
24 | *
25 | * IN
26 | * native - webkit Entry
27 | * OUT
28 | * returns Cordova entry
29 | */
30 |
31 | var info = require('org.apache.cordova.file.bb10FileSystemInfo'),
32 | fileSystems = require('org.apache.cordova.file.fileSystems');
33 |
34 | module.exports = function (native) {
35 | var entry = {
36 | nativeEntry: native,
37 | isDirectory: !!native.isDirectory,
38 | isFile: !!native.isFile,
39 | name: native.name,
40 | fullPath: native.fullPath,
41 | filesystemName: native.filesystem.name,
42 | nativeURL: native.toURL()
43 | },
44 | persistentPath = info.persistentPath.substring(7),
45 | temporaryPath = info.temporaryPath.substring(7);
46 | //fix bb10 webkit incorrect nativeURL
47 | if (native.filesystem.name === 'root') {
48 | entry.nativeURL = 'file:///' + native.fullPath;
49 | } else if (entry.nativeURL.indexOf('filesystem:local:///persistent/') === 0) {
50 | entry.nativeURL = info.persistentPath + native.fullPath;
51 | } else if (entry.nativeURL.indexOf('filesystem:local:///temporary') === 0) {
52 | entry.nativeURL = info.temporaryPath + native.fullPath;
53 | }
54 | //translate file system name from bb10 webkit
55 | if (entry.filesystemName === 'local__0:Persistent' || entry.fullPath.indexOf(persistentPath) !== -1) {
56 | entry.filesystemName = 'persistent';
57 | } else if (entry.filesystemName === 'local__0:Temporary' || entry.fullPath.indexOf(temporaryPath) !== -1) {
58 | entry.filesystemName = 'temporary';
59 | }
60 | //add file system property (will be called sync)
61 | fileSystems.getFs(entry.filesystemName, function (fs) {
62 | entry.filesystem = fs;
63 | });
64 | //set root on fullPath for persistent / temporary locations
65 | entry.fullPath = entry.fullPath.replace(persistentPath, "");
66 | entry.fullPath = entry.fullPath.replace(temporaryPath, "");
67 | //set trailing slash on directory
68 | if (entry.isDirectory && entry.fullPath.substring(entry.fullPath.length - 1) !== '/') {
69 | entry.fullPath += '/';
70 | }
71 | if (entry.isDirectory && entry.nativeURL.substring(entry.nativeURL.length - 1) !== '/') {
72 | entry.nativeURL += '/';
73 | }
74 | //encode URL
75 | entry.nativeURL = window.encodeURI(entry.nativeURL);
76 | return entry;
77 | };
78 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/getDirectory.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * getDirectory
24 | *
25 | * IN:
26 | * args
27 | * 0 - local filesytem URI for the base directory to search
28 | * 1 - directory to be created/returned; may be absolute path or relative path
29 | * 2 - options object
30 | * OUT:
31 | * success - DirectoryEntry
32 | * fail - FileError code
33 | */
34 |
35 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
36 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
37 |
38 | module.exports = function (success, fail, args) {
39 | var uri = args[0] === "/" ? "" : args[0],
40 | dir = args[1],
41 | options = args[2],
42 | onSuccess = function (entry) {
43 | if (typeof(success) === 'function') {
44 | success(entry);
45 | }
46 | },
47 | onFail = function (error) {
48 | if (typeof(fail) === 'function') {
49 | if (error && error.code) {
50 | //set error codes expected by mobile-spec tests
51 | if (error.code === FileError.INVALID_MODIFICATION_ERR && options.exclusive) {
52 | fail(FileError.PATH_EXISTS_ERR);
53 | } else if ( error.code === FileError.NOT_FOUND_ERR && dir.indexOf(':') > 0) {
54 | fail(FileError.ENCODING_ERR);
55 | } else {
56 | fail(error.code);
57 | }
58 | } else {
59 | fail(error);
60 | }
61 | }
62 | };
63 | resolve(function (entry) {
64 | requestAnimationFrame(function () {
65 | entry.nativeEntry.getDirectory(dir, options, function (nativeEntry) {
66 | resolve(function (entry) {
67 | onSuccess(entry);
68 | }, onFail, [uri + "/" + dir]);
69 | }, onFail);
70 | });
71 | }, onFail, [uri]);
72 | };
73 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/getFile.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * getFile
24 | *
25 | * IN:
26 | * args
27 | * 0 - local filesytem URI for the base directory to search
28 | * 1 - file to be created/returned; may be absolute path or relative path
29 | * 2 - options object
30 | * OUT:
31 | * success - FileEntry
32 | * fail - FileError code
33 | */
34 |
35 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy');
36 |
37 | module.exports = function (success, fail, args) {
38 | var uri = args[0] === "/" ? "" : args[0] + "/" + args[1],
39 | options = args[2],
40 | onSuccess = function (entry) {
41 | if (typeof(success) === 'function') {
42 | success(entry);
43 | }
44 | },
45 | onFail = function (code) {
46 | if (typeof(fail) === 'function') {
47 | fail(code);
48 | }
49 | };
50 | resolve(function (entry) {
51 | if (!entry.isFile) {
52 | onFail(FileError.TYPE_MISMATCH_ERR);
53 | } else {
54 | onSuccess(entry);
55 | }
56 | }, onFail, [uri, options]);
57 | };
58 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/getFileMetadata.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * getFileMetadata
24 | *
25 | * IN:
26 | * args
27 | * 0 - local filesytem URI
28 | * OUT:
29 | * success - file
30 | * - name
31 | * - type
32 | * - lastModifiedDate
33 | * - size
34 | * fail - FileError code
35 | */
36 |
37 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
38 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
39 |
40 | module.exports = function (success, fail, args) {
41 | var uri = args[0],
42 | onSuccess = function (entry) {
43 | if (typeof(success) === 'function') {
44 | success(entry);
45 | }
46 | },
47 | onFail = function (error) {
48 | if (typeof(fail) === 'function') {
49 | if (error.code) {
50 | fail(error.code);
51 | } else {
52 | fail(error);
53 | }
54 | }
55 | };
56 | resolve(function (entry) {
57 | requestAnimationFrame(function () {
58 | if (entry.nativeEntry.file) {
59 | entry.nativeEntry.file(onSuccess, onFail);
60 | } else {
61 | entry.nativeEntry.getMetadata(onSuccess, onFail);
62 | }
63 | });
64 | }, onFail, [uri]);
65 | };
66 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/getMetadata.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * getMetadata
24 | *
25 | * IN:
26 | * args
27 | * 0 - local filesytem URI
28 | * OUT:
29 | * success - metadata
30 | * fail - FileError code
31 | */
32 |
33 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy');
34 |
35 | module.exports = function (success, fail, args) {
36 | var uri = args[0],
37 | onSuccess = function (entry) {
38 | if (typeof(success) === 'function') {
39 | success(entry);
40 | }
41 | },
42 | onFail = function (error) {
43 | if (typeof(fail) === 'function') {
44 | if (error.code) {
45 | fail(error.code);
46 | } else {
47 | fail(error);
48 | }
49 | }
50 | };
51 | resolve(function (entry) {
52 | entry.nativeEntry.getMetadata(onSuccess, onFail);
53 | }, onFail, [uri]);
54 | };
55 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/getParent.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * getParent
24 | *
25 | * IN:
26 | * args
27 | * 0 - local filesytem URI
28 | * OUT:
29 | * success - DirectoryEntry of parent
30 | * fail - FileError code
31 | */
32 |
33 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
34 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
35 |
36 | module.exports = function (success, fail, args) {
37 | var uri = args[0],
38 | onSuccess = function (entry) {
39 | if (typeof(success) === 'function') {
40 | success(entry);
41 | }
42 | },
43 | onFail = function (error) {
44 | if (typeof(fail) === 'function') {
45 | if (error && error.code) {
46 | fail(error.code);
47 | } else {
48 | fail(error);
49 | }
50 | }
51 | };
52 | resolve(function (entry) {
53 | requestAnimationFrame(function () {
54 | entry.nativeEntry.getParent(onSuccess, onFail);
55 | });
56 | }, onFail, [uri]);
57 | };
58 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/info.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * info
24 | *
25 | * persistentPath - full path to app sandboxed persistent storage
26 | * temporaryPath - full path to app sandboxed temporary storage
27 | * localPath - full path to app source (www dir)
28 | * MAX_SIZE - maximum size for filesystem request
29 | */
30 |
31 | var info = {
32 | persistentPath: "",
33 | temporaryPath: "",
34 | localPath: "",
35 | MAX_SIZE: 64 * 1024 * 1024 * 1024
36 | };
37 |
38 | cordova.exec(
39 | function (path) {
40 | info.persistentPath = 'file://' + path + '/webviews/webfs/persistent/local__0';
41 | info.temporaryPath = 'file://' + path + '/webviews/webfs/temporary/local__0';
42 | info.localPath = path.replace('/data', '/app/native');
43 | },
44 | function () {
45 | console.error('Unable to determine local storage file path');
46 | },
47 | 'File',
48 | 'getHomePath',
49 | false
50 | );
51 |
52 | module.exports = info;
53 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/moveTo.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * moveTo
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of entry to move
28 | * 1 - URL of the directory into which to move the entry
29 | * 2 - the new name of the entry, defaults to the current name
30 | * OUT:
31 | * success - entry for the copied file or directory
32 | * fail - FileError
33 | */
34 |
35 | var copy = cordova.require('org.apache.cordova.file.copyToProxy');
36 |
37 | module.exports = function (success, fail, args) {
38 | copy(success, fail, args, true);
39 | };
40 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/readAsArrayBuffer.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * readAsArrayBuffer
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of file to read
28 | * 1 - start position
29 | * 2 - end position
30 | * OUT:
31 | * success - ArrayBuffer of file
32 | * fail - FileError
33 | */
34 |
35 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
36 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
37 |
38 | module.exports = function (success, fail, args) {
39 | var uri = args[0],
40 | start = args[1],
41 | end = args[2],
42 | onSuccess = function (data) {
43 | if (typeof success === 'function') {
44 | success(data);
45 | }
46 | },
47 | onFail = function (error) {
48 | if (typeof fail === 'function') {
49 | if (error && error.code) {
50 | fail(error.code);
51 | } else {
52 | fail(error);
53 | }
54 | }
55 | };
56 | resolve(function (fs) {
57 | requestAnimationFrame(function () {
58 | fs.nativeEntry.file(function (file) {
59 | var reader = new FileReader()._realReader;
60 | reader.onloadend = function () {
61 | onSuccess(this.result.slice(start, end));
62 | };
63 | reader.onerror = onFail;
64 | reader.readAsArrayBuffer(file);
65 | }, onFail);
66 | });
67 | }, fail, [uri]);
68 | };
69 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/readAsBinaryString.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * readAsBinaryString
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of file to read
28 | * 1 - start position
29 | * 2 - end position
30 | * OUT:
31 | * success - BinaryString contents of file
32 | * fail - FileError
33 | */
34 |
35 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
36 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
37 |
38 | module.exports = function (success, fail, args) {
39 | var uri = args[0],
40 | start = args[1],
41 | end = args[2],
42 | onSuccess = function (data) {
43 | if (typeof success === 'function') {
44 | success(data);
45 | }
46 | },
47 | onFail = function (error) {
48 | if (typeof fail === 'function') {
49 | if (error && error.code) {
50 | fail(error.code);
51 | } else {
52 | fail(error);
53 | }
54 | }
55 | };
56 | resolve(function (fs) {
57 | requestAnimationFrame(function () {
58 | fs.nativeEntry.file(function (file) {
59 | var reader = new FileReader()._realReader;
60 | reader.onloadend = function () {
61 | onSuccess(this.result.substring(start, end));
62 | };
63 | reader.onerror = onFail;
64 | reader.readAsBinaryString(file);
65 | }, onFail);
66 | });
67 | }, fail, [uri]);
68 | };
69 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/readAsDataURL.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * readAsDataURL
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of file to read
28 | * OUT:
29 | * success - DataURL representation of file contents
30 | * fail - FileError
31 | */
32 |
33 |
34 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
35 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
36 |
37 | module.exports = function (success, fail, args) {
38 | var uri = args[0],
39 | onSuccess = function (data) {
40 | if (typeof success === 'function') {
41 | success(data);
42 | }
43 | },
44 | onFail = function (error) {
45 | if (typeof fail === 'function') {
46 | if (error && error.code) {
47 | fail(error.code);
48 | } else {
49 | fail(error);
50 | }
51 | }
52 | };
53 | resolve(function (fs) {
54 | requestAnimationFrame(function () {
55 | fs.nativeEntry.file(function (file) {
56 | var reader = new FileReader()._realReader;
57 | reader.onloadend = function () {
58 | onSuccess(this.result);
59 | };
60 | reader.onerror = onFail;
61 | reader.readAsDataURL(file);
62 | }, onFail);
63 | });
64 | }, fail, [uri]);
65 | };
66 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/readAsText.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * readAsText
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of file to read
28 | * 1 - encoding
29 | * 2 - start position
30 | * 3 - end position
31 | * OUT:
32 | * success - text contents of file
33 | * fail - FileError
34 | */
35 |
36 |
37 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
38 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
39 |
40 | module.exports = function (success, fail, args) {
41 | var uri = args[0],
42 | start = args[2],
43 | end = args[3],
44 | onSuccess = function (data) {
45 | if (typeof success === 'function') {
46 | success(data);
47 | }
48 | },
49 | onFail = function (error) {
50 | if (typeof fail === 'function') {
51 | if (error && error.code) {
52 | fail(error.code);
53 | } else {
54 | fail(error);
55 | }
56 | }
57 | };
58 | resolve(function (fs) {
59 | requestAnimationFrame(function () {
60 | fs.nativeEntry.file(function (file) {
61 | var reader = new FileReader()._realReader;
62 | reader.onloadend = function () {
63 | var contents = new Uint8Array(this.result).subarray(start, end),
64 | blob = new Blob([contents]),
65 | textReader = new FileReader()._realReader;
66 | textReader.onloadend = function () {
67 | onSuccess(this.result);
68 | };
69 | textReader.onerror = onFail;
70 | textReader.readAsText(blob);
71 | };
72 | reader.onerror = onFail;
73 | reader.readAsArrayBuffer(file);
74 | }, onFail);
75 | });
76 | }, fail, [uri]);
77 | };
78 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/readEntries.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * readEntries
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of directory to list
28 | * OUT:
29 | * success - Array of Entry objects
30 | * fail - FileError
31 | */
32 |
33 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
34 | info = require('org.apache.cordova.file.bb10FileSystemInfo'),
35 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame'),
36 | createEntryFromNative = cordova.require('org.apache.cordova.file.bb10CreateEntryFromNative');
37 |
38 | module.exports = function (success, fail, args) {
39 | var uri = args[0],
40 | onSuccess = function (data) {
41 | if (typeof success === 'function') {
42 | success(data);
43 | }
44 | },
45 | onFail = function (error) {
46 | if (typeof fail === 'function') {
47 | if (error.code) {
48 | fail(error.code);
49 | } else {
50 | fail(error);
51 | }
52 | }
53 | };
54 | resolve(function (fs) {
55 | requestAnimationFrame(function () {
56 | var reader = fs.nativeEntry.createReader(),
57 | entries = [],
58 | readEntries = function() {
59 | reader.readEntries(function (results) {
60 | if (!results.length) {
61 | onSuccess(entries.sort().map(createEntryFromNative));
62 | } else {
63 | entries = entries.concat(Array.prototype.slice.call(results || [], 0));
64 | readEntries();
65 | }
66 | }, onFail);
67 | };
68 | readEntries();
69 | });
70 | }, fail, [uri]);
71 | };
72 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/remove.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * remove
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of Entry to remove
28 | * OUT:
29 | * success - (no args)
30 | * fail - FileError
31 | */
32 |
33 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
34 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
35 |
36 | module.exports = function (success, fail, args) {
37 | var uri = args[0],
38 | onSuccess = function (data) {
39 | if (typeof success === 'function') {
40 | success(data);
41 | }
42 | },
43 | onFail = function (error) {
44 | if (typeof fail === 'function') {
45 | if (error && error.code) {
46 | fail(error.code);
47 | } else {
48 | fail(error);
49 | }
50 | }
51 | };
52 | resolve(function (fs) {
53 | requestAnimationFrame(function () {
54 | if (fs.fullPath === '/') {
55 | onFail(FileError.NO_MODIFICATION_ALLOWED_ERR);
56 | } else {
57 | fs.nativeEntry.remove(onSuccess, onFail);
58 | }
59 | });
60 | }, fail, [uri]);
61 | };
62 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/removeRecursively.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * removeRecursively
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of DirectoryEntry to remove recursively
28 | * OUT:
29 | * success - (no args)
30 | * fail - FileError
31 | */
32 |
33 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
34 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
35 |
36 | module.exports = function (success, fail, args) {
37 | var uri = args[0],
38 | onSuccess = function (data) {
39 | if (typeof success === 'function') {
40 | success(data);
41 | }
42 | },
43 | onFail = function (error) {
44 | if (typeof fail === 'function') {
45 | if (error.code) {
46 | if (error.code === FileError.INVALID_MODIFICATION_ERR) {
47 | //mobile-spec expects this error code
48 | fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
49 | } else {
50 | fail(error.code);
51 | }
52 | } else {
53 | fail(error);
54 | }
55 | }
56 | };
57 | resolve(function (fs) {
58 | requestAnimationFrame(function () {
59 | fs.nativeEntry.removeRecursively(onSuccess, onFail);
60 | });
61 | }, fail, [uri]);
62 | };
63 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/requestAllFileSystems.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * requestAllFileSystems
24 | *
25 | * IN - no arguments
26 | * OUT
27 | * success - Array of FileSystems
28 | * - filesystemName
29 | * - fullPath
30 | * - name
31 | * - nativeURL
32 | */
33 |
34 | var info = require('org.apache.cordova.file.bb10FileSystemInfo');
35 |
36 | module.exports = function (success, fail, args) {
37 | success([
38 | { filesystemName: 'persistent', name: 'persistent', fullPath: '/', nativeURL: info.persistentPath + '/' },
39 | { filesystemName: 'temporary', name: 'temporary', fullPath: '/', nativeURL: info.temporaryPath + '/' },
40 | { filesystemName: 'root', name: 'root', fullPath: '/', nativeURL: 'file:///' }
41 | ]);
42 | }
43 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/requestAnimationFrame.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * requestAnimationFrame
24 | *
25 | * This is used throughout the BB10 File implementation to wrap
26 | * native webkit calls. There is a bug in the webkit implementation
27 | * which causes callbacks to never return when multiple file system
28 | * APIs are called in sequence. This should also make the UI more
29 | * responsive during file operations.
30 | *
31 | * Supported on BB10 OS > 10.1
32 | */
33 |
34 | var requestAnimationFrame = window.requestAnimationFrame;
35 | if (typeof(requestAnimationFrame) !== 'function') {
36 | requestAnimationFrame = function (cb) { cb(); };
37 | }
38 | module.exports = requestAnimationFrame;
39 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/requestFileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * requestFileSystem
24 | *
25 | * IN:
26 | * args
27 | * 0 - type (TEMPORARY = 0, PERSISTENT = 1)
28 | * 1 - size
29 | * OUT:
30 | * success - FileSystem object
31 | * - name - the human readable directory name
32 | * - root - DirectoryEntry object
33 | * - isDirectory
34 | * - isFile
35 | * - name
36 | * - fullPath
37 | * fail - FileError code
38 | */
39 |
40 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy');
41 |
42 | module.exports = function (success, fail, args) {
43 | var fsType = args[0] === 0 ? 'temporary' : 'persistent',
44 | size = args[1],
45 | onSuccess = function (fs) {
46 | var directory = {
47 | name: fsType,
48 | root: fs
49 | };
50 | success(directory);
51 | };
52 | resolve(onSuccess, fail, ['cdvfile://localhost/' + fsType + '/', undefined, size]);
53 | };
54 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/setMetadata.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * setMetadata
24 | *
25 | * BB10 OS does not support setting file metadata via HTML5 File System
26 | */
27 |
28 | module.exports = function (success, fail, args) {
29 | console.error("setMetadata not supported on BB10", arguments);
30 | if (typeof(fail) === 'function') {
31 | fail();
32 | }
33 | };
34 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/truncate.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * truncate
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of file to truncate
28 | * 1 - start position
29 | * OUT:
30 | * success - new length of file
31 | * fail - FileError
32 | */
33 |
34 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
35 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
36 |
37 | module.exports = function (success, fail, args) {
38 | var uri = args[0],
39 | length = args[1],
40 | onSuccess = function (data) {
41 | if (typeof success === 'function') {
42 | success(data.loaded);
43 | }
44 | },
45 | onFail = function (error) {
46 | if (typeof fail === 'function') {
47 | if (error && error.code) {
48 | fail(error.code);
49 | } else {
50 | fail(error);
51 | }
52 | }
53 | };
54 | resolve(function (fs) {
55 | requestAnimationFrame(function () {
56 | fs.nativeEntry.file(function (file) {
57 | var reader = new FileReader()._realReader;
58 | reader.onloadend = function () {
59 | var contents = new Uint8Array(this.result).subarray(0, length);
60 | blob = new Blob([contents]);
61 | window.requestAnimationFrame(function () {
62 | fs.nativeEntry.createWriter(function (fileWriter) {
63 | fileWriter.onwriteend = onSuccess;
64 | fileWriter.onerror = onFail;
65 | fileWriter.write(blob);
66 | }, onFail);
67 | });
68 | };
69 | reader.onerror = onFail;
70 | reader.readAsArrayBuffer(file);
71 | }, onFail);
72 | });
73 | }, onFail, [uri]);
74 | };
75 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/blackberry10/write.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /*
23 | * write
24 | *
25 | * IN:
26 | * args
27 | * 0 - URL of file to write
28 | * 1 - data to write
29 | * 2 - offset
30 | * 3 - isBinary
31 | * OUT:
32 | * success - bytes written
33 | * fail - FileError
34 | */
35 |
36 | var resolve = cordova.require('org.apache.cordova.file.resolveLocalFileSystemURIProxy'),
37 | requestAnimationFrame = cordova.require('org.apache.cordova.file.bb10RequestAnimationFrame');
38 |
39 | module.exports = function (success, fail, args) {
40 | var uri = args[0],
41 | data = args[1],
42 | offset = args[2],
43 | isBinary = args[3],
44 | onSuccess = function (data) {
45 | if (typeof success === 'function') {
46 | success(data.loaded);
47 | }
48 | },
49 | onFail = function (error) {
50 | if (typeof fail === 'function') {
51 | if (error && error.code) {
52 | fail(error.code);
53 | } else if (error && error.target && error.target.code) {
54 | fail(error.target.code);
55 | } else {
56 | fail(error);
57 | }
58 | }
59 | };
60 | resolve(function (fs) {
61 | requestAnimationFrame(function () {
62 | fs.nativeEntry.createWriter(function (writer) {
63 | var blob = new Blob([data]);
64 | if (offset) {
65 | writer.seek(offset);
66 | }
67 | writer.onwriteend = onSuccess;
68 | writer.onerror = onFail;
69 | writer.write(blob);
70 | }, onFail);
71 | });
72 | }, fail, [uri, { create: true }]);
73 | };
74 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/fileSystemPaths.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var exec = require('cordova/exec');
23 | var channel = require('cordova/channel');
24 |
25 | exports.file = {
26 | // Read-only directory where the application is installed.
27 | applicationDirectory: null,
28 | // Root of app's private writable storage
29 | applicationStorageDirectory: null,
30 | // Where to put app-specific data files.
31 | dataDirectory: null,
32 | // Cached files that should survive app restarts.
33 | // Apps should not rely on the OS to delete files in here.
34 | cacheDirectory: null,
35 | // Android: the application space on external storage.
36 | externalApplicationStorageDirectory: null,
37 | // Android: Where to put app-specific data files on external storage.
38 | externalDataDirectory: null,
39 | // Android: the application cache on external storage.
40 | externalCacheDirectory: null,
41 | // Android: the external storage (SD card) root.
42 | externalRootDirectory: null,
43 | // iOS: Temp directory that the OS can clear at will.
44 | tempDirectory: null,
45 | // iOS: Holds app-specific files that should be synced (e.g. to iCloud).
46 | syncedDataDirectory: null,
47 | // iOS: Files private to the app, but that are meaningful to other applciations (e.g. Office files)
48 | documentsDirectory: null,
49 | // BlackBerry10: Files globally available to all apps
50 | sharedDirectory: null
51 | };
52 |
53 | channel.waitForInitialization('onFileSystemPathsReady');
54 | channel.onCordovaReady.subscribe(function() {
55 | function after(paths) {
56 | for (var k in paths) {
57 | exports.file[k] = paths[k];
58 | }
59 | channel.initializationComplete('onFileSystemPathsReady');
60 | }
61 | exec(after, null, 'File', 'requestAllPaths', []);
62 | });
63 |
64 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/fileSystems-roots.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | // Map of fsName -> FileSystem.
23 | var fsMap = null;
24 | var FileSystem = require('./FileSystem');
25 | var exec = require('cordova/exec');
26 |
27 | // Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
28 | require('./fileSystems').getFs = function(name, callback) {
29 | if (fsMap) {
30 | callback(fsMap[name]);
31 | } else {
32 | exec(success, null, "File", "requestAllFileSystems", []);
33 | function success(response) {
34 | fsMap = {};
35 | for (var i = 0; i < response.length; ++i) {
36 | var fsRoot = response[i];
37 | var fs = new FileSystem(fsRoot.filesystemName, fsRoot);
38 | fsMap[fs.name] = fs;
39 | }
40 | callback(fsMap[name]);
41 | }
42 | }
43 | };
44 |
45 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/fileSystems.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | // Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
23 | module.exports.getFs = function(name, callback) {
24 | callback(null);
25 | };
26 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/firefoxos/FileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | FILESYSTEM_PREFIX = "file:///";
23 |
24 | module.exports = {
25 | __format__: function(fullPath) {
26 | return (FILESYSTEM_PREFIX + this.name + (fullPath[0] === '/' ? '' : '/') + encodeURI(fullPath));
27 | }
28 | };
29 |
30 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/ios/FileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | FILESYSTEM_PROTOCOL = "cdvfile";
23 |
24 | module.exports = {
25 | __format__: function(fullPath) {
26 | var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
27 | return FILESYSTEM_PROTOCOL + '://localhost' + path;
28 | }
29 | };
30 |
31 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/requestFileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var argscheck = require('cordova/argscheck'),
23 | FileError = require('./FileError'),
24 | FileSystem = require('./FileSystem'),
25 | exec = require('cordova/exec');
26 | var fileSystems = require('./fileSystems');
27 |
28 | /**
29 | * Request a file system in which to store application data.
30 | * @param type local file system type
31 | * @param size indicates how much storage space, in bytes, the application expects to need
32 | * @param successCallback invoked with a FileSystem object
33 | * @param errorCallback invoked if error occurs retrieving file system
34 | */
35 | var requestFileSystem = function(type, size, successCallback, errorCallback) {
36 | argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
37 | var fail = function(code) {
38 | errorCallback && errorCallback(new FileError(code));
39 | };
40 |
41 | if (type < 0) {
42 | fail(FileError.SYNTAX_ERR);
43 | } else {
44 | // if successful, return a FileSystem object
45 | var success = function(file_system) {
46 | if (file_system) {
47 | if (successCallback) {
48 | fileSystems.getFs(file_system.name, function(fs) {
49 | if (!fs) {
50 | fs = new FileSystem(file_system.name, file_system.root);
51 | }
52 | successCallback(fs);
53 | });
54 | }
55 | }
56 | else {
57 | // no FileSystem object returned
58 | fail(FileError.NOT_FOUND_ERR);
59 | }
60 | };
61 | exec(success, fail, "File", "requestFileSystem", [type, size]);
62 | }
63 | };
64 |
65 | module.exports = requestFileSystem;
66 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/resolveLocalFileSystemURI.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var argscheck = require('cordova/argscheck'),
23 | DirectoryEntry = require('./DirectoryEntry'),
24 | FileEntry = require('./FileEntry'),
25 | FileError = require('./FileError'),
26 | exec = require('cordova/exec');
27 | var fileSystems = require('./fileSystems');
28 |
29 | /**
30 | * Look up file system Entry referred to by local URI.
31 | * @param {DOMString} uri URI referring to a local file or directory
32 | * @param successCallback invoked with Entry object corresponding to URI
33 | * @param errorCallback invoked if error occurs retrieving file system entry
34 | */
35 | module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorCallback) {
36 | argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
37 | // error callback
38 | var fail = function(error) {
39 | errorCallback && errorCallback(new FileError(error));
40 | };
41 | // sanity check for 'not:valid:filename' or '/not:valid:filename'
42 | // file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
43 | if(!uri || uri.split(":").length > 2) {
44 | setTimeout( function() {
45 | fail(FileError.ENCODING_ERR);
46 | },0);
47 | return;
48 | }
49 | // if successful, return either a file or directory entry
50 | var success = function(entry) {
51 | if (entry) {
52 | if (successCallback) {
53 | // create appropriate Entry object
54 | var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
55 | fileSystems.getFs(fsName, function(fs) {
56 | if (!fs) {
57 | fs = new FileSystem(fsName, {name:"", fullPath:"/"});
58 | }
59 | var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
60 | successCallback(result);
61 | });
62 | }
63 | }
64 | else {
65 | // no Entry object returned
66 | fail(FileError.NOT_FOUND_ERR);
67 | }
68 | };
69 |
70 | exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
71 | };
72 | module.exports.resolveLocalFileSystemURI = function() {
73 | console.log("resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.");
74 | module.exports.resolveLocalFileSystemURL.apply(this, arguments);
75 | };
76 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/ubuntu/FileSystem.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | FILESYSTEM_PROTOCOL = "cdvfile";
23 |
24 | module.exports = {
25 | __format__: function(fullPath) {
26 | if (this.name === 'content') {
27 | return 'content:/' + fullPath;
28 | }
29 | var path = ('/' + this.name + (fullPath[0] === '/' ? '' : '/') + encodeURI(fullPath)).replace('//','/');
30 |
31 | return FILESYSTEM_PROTOCOL + '://localhost' + path;
32 | }
33 | };
34 |
35 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/ubuntu/FileWriter.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var exec = require('cordova/exec'),
23 | FileError = require('./FileError'),
24 | ProgressEvent = require('./ProgressEvent');
25 |
26 | function write(data) {
27 | var that=this;
28 | var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
29 | var isBinary;
30 |
31 | // Check to see if the incoming data is a blob
32 | if (data instanceof File || (supportsBinary && data instanceof Blob)) {
33 | var fileReader = new FileReader();
34 | fileReader.onload = function() {
35 | // Call this method again, with the arraybuffer as argument
36 | FileWriter.prototype.write.call(that, this.result);
37 | };
38 | if (supportsBinary) {
39 | fileReader.readAsArrayBuffer(data);
40 | } else {
41 | fileReader.readAsText(data);
42 | }
43 | return;
44 | }
45 |
46 | // Mark data type for safer transport over the binary bridge
47 | isBinary = supportsBinary && (data instanceof ArrayBuffer);
48 |
49 | // Throw an exception if we are already writing a file
50 | if (this.readyState === FileWriter.WRITING) {
51 | throw new FileError(FileError.INVALID_STATE_ERR);
52 | }
53 |
54 | // WRITING state
55 | this.readyState = FileWriter.WRITING;
56 |
57 | var me = this;
58 |
59 | // If onwritestart callback
60 | if (typeof me.onwritestart === "function") {
61 | me.onwritestart(new ProgressEvent("writestart", {"target":me}));
62 | }
63 |
64 | if (data instanceof ArrayBuffer || data.buffer instanceof ArrayBuffer) {
65 | data = new Uint8Array(data);
66 | var binary = "";
67 | for (var i = 0; i < data.byteLength; i++) {
68 | binary += String.fromCharCode(data[i]);
69 | }
70 | data = binary;
71 | }
72 |
73 | var prefix = "file://localhost";
74 | var path = this.localURL;
75 | if (path.substr(0, prefix.length) == prefix) {
76 | path = path.substr(prefix.length);
77 | }
78 | // Write file
79 | exec(
80 | // Success callback
81 | function(r) {
82 | // If DONE (cancelled), then don't do anything
83 | if (me.readyState === FileWriter.DONE) {
84 | return;
85 | }
86 |
87 | // position always increases by bytes written because file would be extended
88 | me.position += r;
89 | // The length of the file is now where we are done writing.
90 |
91 | me.length = me.position;
92 |
93 | // DONE state
94 | me.readyState = FileWriter.DONE;
95 |
96 | // If onwrite callback
97 | if (typeof me.onwrite === "function") {
98 | me.onwrite(new ProgressEvent("write", {"target":me}));
99 | }
100 |
101 | // If onwriteend callback
102 | if (typeof me.onwriteend === "function") {
103 | me.onwriteend(new ProgressEvent("writeend", {"target":me}));
104 | }
105 | },
106 | // Error callback
107 | function(e) {
108 | // If DONE (cancelled), then don't do anything
109 | if (me.readyState === FileWriter.DONE) {
110 | return;
111 | }
112 |
113 | // DONE state
114 | me.readyState = FileWriter.DONE;
115 |
116 | // Save error
117 | me.error = new FileError(e);
118 |
119 | // If onerror callback
120 | if (typeof me.onerror === "function") {
121 | me.onerror(new ProgressEvent("error", {"target":me}));
122 | }
123 |
124 | // If onwriteend callback
125 | if (typeof me.onwriteend === "function") {
126 | me.onwriteend(new ProgressEvent("writeend", {"target":me}));
127 | }
128 | }, "File", "write", [path, data, this.position, isBinary]);
129 | };
130 |
131 | module.exports = {
132 | write: write
133 | };
134 |
135 | require("cordova/exec/proxy").add("FileWriter", module.exports);
136 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/ubuntu/fileSystems-roots.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | var fsMap = null;
23 | var FileSystem = require('./FileSystem');
24 | var LocalFileSystem = require('./LocalFileSystem');
25 | var exec = require('cordova/exec');
26 |
27 | var requestFileSystem = function(type, size, successCallback) {
28 | var success = function(file_system) {
29 | if (file_system) {
30 | if (successCallback) {
31 | fs = new FileSystem(file_system.name, file_system.root);
32 | successCallback(fs);
33 | }
34 | }
35 | };
36 | exec(success, null, "File", "requestFileSystem", [type, size]);
37 | };
38 |
39 | require('./fileSystems').getFs = function(name, callback) {
40 | if (fsMap) {
41 | callback(fsMap[name]);
42 | } else {
43 | requestFileSystem(LocalFileSystem.PERSISTENT, 1, function(fs) {
44 | requestFileSystem(LocalFileSystem.TEMPORARY, 1, function(tmp) {
45 | fsMap = {};
46 | fsMap[tmp.name] = tmp;
47 | fsMap[fs.name] = fs;
48 | callback(fsMap[name]);
49 | });
50 | });
51 | }
52 | };
53 |
54 |
--------------------------------------------------------------------------------
/cordova/plugins/org.apache.cordova.file/www/wp/FileUploadOptions.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | */
21 |
22 | /**
23 | * Options to customize the HTTP request used to upload files.
24 | * @constructor
25 | * @param fileKey {String} Name of file request parameter.
26 | * @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
27 | * @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
28 | * @param params {Object} Object with key: value params to send to the server.
29 | */
30 | var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers, httpMethod) {
31 | this.fileKey = fileKey || null;
32 | this.fileName = fileName || null;
33 | this.mimeType = mimeType || null;
34 | this.headers = headers || null;
35 | this.httpMethod = httpMethod || null;
36 |
37 | if(params && typeof params != typeof "") {
38 | var arrParams = [];
39 | for(var v in params) {
40 | arrParams.push(v + "=" + params[v]);
41 | }
42 | this.params = encodeURIComponent(arrParams.join("&"));
43 | }
44 | else {
45 | this.params = params || null;
46 | }
47 | };
48 |
49 | module.exports = FileUploadOptions;
50 |
--------------------------------------------------------------------------------
/cordova/www/img/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanshortiss/html5-fs/a1ef381034649c767d1f38f4fb31ea13f8767c80/cordova/www/img/logo.png
--------------------------------------------------------------------------------
/cordova/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | FS Test
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/cordova/www/mocha.css:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | body {
4 | margin:0;
5 | }
6 |
7 | #mocha {
8 | font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
9 | margin: 60px 50px;
10 | }
11 |
12 | #mocha ul,
13 | #mocha li {
14 | margin: 0;
15 | padding: 0;
16 | }
17 |
18 | #mocha ul {
19 | list-style: none;
20 | }
21 |
22 | #mocha h1,
23 | #mocha h2 {
24 | margin: 0;
25 | }
26 |
27 | #mocha h1 {
28 | margin-top: 15px;
29 | font-size: 1em;
30 | font-weight: 200;
31 | }
32 |
33 | #mocha h1 a {
34 | text-decoration: none;
35 | color: inherit;
36 | }
37 |
38 | #mocha h1 a:hover {
39 | text-decoration: underline;
40 | }
41 |
42 | #mocha .suite .suite h1 {
43 | margin-top: 0;
44 | font-size: .8em;
45 | }
46 |
47 | #mocha .hidden {
48 | display: none;
49 | }
50 |
51 | #mocha h2 {
52 | font-size: 12px;
53 | font-weight: normal;
54 | cursor: pointer;
55 | }
56 |
57 | #mocha .suite {
58 | margin-left: 15px;
59 | }
60 |
61 | #mocha .test {
62 | margin-left: 15px;
63 | overflow: hidden;
64 | }
65 |
66 | #mocha .test.pending:hover h2::after {
67 | content: '(pending)';
68 | font-family: arial, sans-serif;
69 | }
70 |
71 | #mocha .test.pass.medium .duration {
72 | background: #c09853;
73 | }
74 |
75 | #mocha .test.pass.slow .duration {
76 | background: #b94a48;
77 | }
78 |
79 | #mocha .test.pass::before {
80 | content: '✓';
81 | font-size: 12px;
82 | display: block;
83 | float: left;
84 | margin-right: 5px;
85 | color: #00d6b2;
86 | }
87 |
88 | #mocha .test.pass .duration {
89 | font-size: 9px;
90 | margin-left: 5px;
91 | padding: 2px 5px;
92 | color: #fff;
93 | -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
94 | -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
95 | box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
96 | -webkit-border-radius: 5px;
97 | -moz-border-radius: 5px;
98 | -ms-border-radius: 5px;
99 | -o-border-radius: 5px;
100 | border-radius: 5px;
101 | }
102 |
103 | #mocha .test.pass.fast .duration {
104 | display: none;
105 | }
106 |
107 | #mocha .test.pending {
108 | color: #0b97c4;
109 | }
110 |
111 | #mocha .test.pending::before {
112 | content: '◦';
113 | color: #0b97c4;
114 | }
115 |
116 | #mocha .test.fail {
117 | color: #c00;
118 | }
119 |
120 | #mocha .test.fail pre {
121 | color: black;
122 | }
123 |
124 | #mocha .test.fail::before {
125 | content: '✖';
126 | font-size: 12px;
127 | display: block;
128 | float: left;
129 | margin-right: 5px;
130 | color: #c00;
131 | }
132 |
133 | #mocha .test pre.error {
134 | color: #c00;
135 | max-height: 300px;
136 | overflow: auto;
137 | }
138 |
139 | /**
140 | * (1): approximate for browsers not supporting calc
141 | * (2): 42 = 2*15 + 2*10 + 2*1 (padding + margin + border)
142 | * ^^ seriously
143 | */
144 | #mocha .test pre {
145 | display: block;
146 | float: left;
147 | clear: left;
148 | font: 12px/1.5 monaco, monospace;
149 | margin: 5px;
150 | padding: 15px;
151 | border: 1px solid #eee;
152 | max-width: 85%; /*(1)*/
153 | max-width: calc(100% - 42px); /*(2)*/
154 | word-wrap: break-word;
155 | border-bottom-color: #ddd;
156 | -webkit-border-radius: 3px;
157 | -webkit-box-shadow: 0 1px 3px #eee;
158 | -moz-border-radius: 3px;
159 | -moz-box-shadow: 0 1px 3px #eee;
160 | border-radius: 3px;
161 | }
162 |
163 | #mocha .test h2 {
164 | position: relative;
165 | }
166 |
167 | #mocha .test a.replay {
168 | position: absolute;
169 | top: 3px;
170 | right: 0;
171 | text-decoration: none;
172 | vertical-align: middle;
173 | display: block;
174 | width: 15px;
175 | height: 15px;
176 | line-height: 15px;
177 | text-align: center;
178 | background: #eee;
179 | font-size: 15px;
180 | -moz-border-radius: 15px;
181 | border-radius: 15px;
182 | -webkit-transition: opacity 200ms;
183 | -moz-transition: opacity 200ms;
184 | transition: opacity 200ms;
185 | opacity: 0.3;
186 | color: #888;
187 | }
188 |
189 | #mocha .test:hover a.replay {
190 | opacity: 1;
191 | }
192 |
193 | #mocha-report.pass .test.fail {
194 | display: none;
195 | }
196 |
197 | #mocha-report.fail .test.pass {
198 | display: none;
199 | }
200 |
201 | #mocha-report.pending .test.pass,
202 | #mocha-report.pending .test.fail {
203 | display: none;
204 | }
205 | #mocha-report.pending .test.pass.pending {
206 | display: block;
207 | }
208 |
209 | #mocha-error {
210 | color: #c00;
211 | font-size: 1.5em;
212 | font-weight: 100;
213 | letter-spacing: 1px;
214 | }
215 |
216 | #mocha-stats {
217 | position: fixed;
218 | top: 15px;
219 | right: 10px;
220 | font-size: 12px;
221 | margin: 0;
222 | color: #888;
223 | z-index: 1;
224 | }
225 |
226 | #mocha-stats .progress {
227 | float: right;
228 | padding-top: 0;
229 | }
230 |
231 | #mocha-stats em {
232 | color: black;
233 | }
234 |
235 | #mocha-stats a {
236 | text-decoration: none;
237 | color: inherit;
238 | }
239 |
240 | #mocha-stats a:hover {
241 | border-bottom: 1px solid #eee;
242 | }
243 |
244 | #mocha-stats li {
245 | display: inline-block;
246 | margin: 0 5px;
247 | list-style: none;
248 | padding-top: 11px;
249 | }
250 |
251 | #mocha-stats canvas {
252 | width: 40px;
253 | height: 40px;
254 | }
255 |
256 | #mocha code .comment { color: #ddd; }
257 | #mocha code .init { color: #2f6fad; }
258 | #mocha code .string { color: #5890ad; }
259 | #mocha code .keyword { color: #8a6343; }
260 | #mocha code .number { color: #2f6fad; }
261 |
262 | @media screen and (max-device-width: 480px) {
263 | #mocha {
264 | margin: 60px 0px;
265 | }
266 |
267 | #mocha #stats {
268 | position: absolute;
269 | }
270 | }
271 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration
2 | // Generated on Fri Apr 11 2014 19:16:59 GMT-0400 (EDT)
3 |
4 | module.exports = function(config) {
5 | config.set({
6 |
7 | // base path that will be used to resolve all patterns (eg. files, exclude)
8 | basePath: '',
9 |
10 |
11 | // frameworks to use
12 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13 | frameworks: ['mocha', 'chai'],
14 |
15 |
16 | // list of files / patterns to load in the browser
17 | files: [
18 | './cordova/www/test/*.js'
19 | ],
20 |
21 |
22 | // list of files to exclude
23 | exclude: [
24 |
25 | ],
26 |
27 |
28 | // preprocess matching files before serving them to the browser
29 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
30 | preprocessors: {
31 |
32 | },
33 |
34 |
35 | // test results reporter to use
36 | // possible values: 'dots', 'progress'
37 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter
38 | reporters: ['mocha'],
39 |
40 |
41 | // web server port
42 | port: 9876,
43 |
44 |
45 | // enable / disable colors in the output (reporters and logs)
46 | colors: true,
47 |
48 |
49 | // level of logging
50 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
51 | logLevel: config.LOG_INFO,
52 |
53 |
54 | // enable / disable watching file and executing tests whenever any file changes
55 | autoWatch: false,
56 |
57 |
58 | // start these browsers
59 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
60 | browsers: ['Chrome'],
61 |
62 | // Continuous Integration mode
63 | // if true, Karma captures browsers, runs the tests and exits
64 | singleRun: true
65 | });
66 | };
67 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "html5-fs",
3 | "version": "0.1.1",
4 | "description": "Node.js style wrapper for the HTML5/Cordova FileSytem API.",
5 | "main": "./src/api.js",
6 | "scripts": {
7 | "test": "npm install && grunt test"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git://github.com/evanshortiss/html5-fs.git"
12 | },
13 | "keywords": [
14 | "fs",
15 | "browser",
16 | "browserify",
17 | "node",
18 | "html5",
19 | "file",
20 | "file system",
21 | "FileSystem"
22 | ],
23 | "authors": [
24 | "Evan Shortiss"
25 | ],
26 | "license": "MIT",
27 | "bugs": {
28 | "url": "https://github.com/evanshortiss/html5-fs/issues"
29 | },
30 | "homepage": "https://github.com/evanshortiss/html5-fs",
31 | "devDependencies": {
32 | "chai": "^3.5.0",
33 | "grunt": "~1.0.1",
34 | "grunt-browserify": "^5.0.0",
35 | "grunt-contrib-concat": "~1.0.1",
36 | "grunt-contrib-copy": "^1.0.0",
37 | "grunt-contrib-jshint": "~1.0.0",
38 | "grunt-contrib-nodeunit": "~1.0.0",
39 | "grunt-contrib-uglify": "~2.0.0",
40 | "grunt-cordovacli": "^1.0.1",
41 | "grunt-karma": "~2.0.0",
42 | "grunt-lintspaces": "^0.8.0",
43 | "grunt-mocha-test": "~0.12.7",
44 | "grunt-shell": "~1.3.0",
45 | "karma": "~1.1.2",
46 | "karma-chai": "~0.1.0",
47 | "karma-chrome-launcher": "~1.0.1",
48 | "karma-mocha": "~1.1.1",
49 | "karma-mocha-reporter": "~2.1.0",
50 | "karma-opera-launcher": "^1.0.0",
51 | "linelint": "~1.0.0",
52 | "load-grunt-tasks": "~3.5.0",
53 | "mocha": "^3.0.2"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/api.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var utils = require('./utils')
4 | , pathm = require('path')
5 | , fs = require('./fileSystem');
6 |
7 | var wrapSuccess = utils.wrapSuccess
8 | , wrapFail = utils.wrapFail;
9 |
10 | exports.getFsInstance = fs.getInstance;
11 |
12 | exports.appendFile = function(path, data, callback) {
13 | fs.writeFile(path, data, callback, true);
14 | };
15 |
16 |
17 | exports.writeFile = function(path, data, callback) {
18 | fs.writeFile(path, data, callback, false);
19 | };
20 |
21 |
22 | exports.readFile = function(path, opts, callback) {
23 | if (typeof opts === 'function') {
24 | callback = opts;
25 | opts = {
26 | encoding: 'utf8'
27 | };
28 | }
29 |
30 | var success = wrapSuccess(callback)
31 | , fail = wrapFail(callback);
32 |
33 | fs.getFile(path, function(err, fileEntry) {
34 | fileEntry.file(function(file) {
35 | var reader = new FileReader();
36 |
37 | reader.onloadend = function(evt) {
38 | success(evt.target.result);
39 | };
40 |
41 | reader.onerror = function(err) {
42 | fail(err);
43 | };
44 |
45 | if (opts.encoding === 'utf8') {
46 | reader.readAsText(file);
47 | } else {
48 | reader.readAsDataURL(file);
49 | }
50 | }, fail);
51 | });
52 | };
53 |
54 |
55 | exports.unlink = function(path, callback) {
56 | var success = wrapSuccess(callback)
57 | , fail = wrapFail(callback);
58 |
59 | fs.getFile(path, function(err, file) {
60 | if (err) {
61 | fail(err);
62 | } else {
63 | file.remove(success, fail);
64 | }
65 | });
66 | };
67 |
68 |
69 | exports.readdir = function(path, callback) {
70 | var success = wrapSuccess(callback)
71 | , fail = wrapFail(callback);
72 |
73 | fs.getDirectory(path, function(err, dirEntry) {
74 | if (err) {
75 | fail(err);
76 | } else {
77 | var directoryReader = dirEntry.createReader();
78 | directoryReader.readEntries(success, fail);
79 | }
80 | });
81 | };
82 |
83 |
84 | exports.mkdir = function(path, callback) {
85 | var newFolderName = pathm.basename(path)
86 | , basePath = pathm.dirname(path)
87 | , success = utils.wrapSuccess(callback)
88 | , fail = utils.wrapFail(callback)
89 | , opts = {
90 | create: true,
91 | exclusive: true
92 | };
93 |
94 | if (basePath === '.') {
95 | fs.getDirectory(newFolderName, opts, callback);
96 | } else {
97 | fs.getDirectory(basePath, function (err, dir) {
98 | if (err) {
99 | callback(err, null);
100 | } else {
101 | dir.getDirectory(newFolderName, opts, success, fail);
102 | }
103 | });
104 | }
105 | };
106 |
107 |
108 | /**
109 | * Remove a directory.
110 | * The FileSystem API expects directories to be empty but returns a
111 | * non-informative error on Android and possibly iOS so we check here
112 | * to ensure users know why directory deletes might fail.
113 | * @param {String} path
114 | * @param {Function} callback
115 | */
116 | exports.rmdir = function(path, callback) {
117 | var success = wrapSuccess(callback)
118 | , fail = wrapFail(callback);
119 |
120 | this.readdir(path, function(err, list) {
121 | if (err) {
122 | fail(err);
123 | } else if (list && list.length > 0) {
124 | fail('ENOTEMPTY: Directory must be empty');
125 | } else {
126 | fs.getDirectory(path, function(err, dirEntry) {
127 | if (err) {
128 | fail(err);
129 | } else {
130 | dirEntry.remove(success, fail);
131 | }
132 | });
133 | }
134 | });
135 | };
136 |
137 |
138 | exports.exists = function(path, callback) {
139 | var fail = wrapFail(callback);
140 |
141 | fs.getFile(path, {
142 | // Don't create the file, just look for it
143 | create: false
144 | }, function(err) {
145 | // See https://www.chromestatus.com/features/6687420359639040.
146 | if (err &&
147 | ((window.FileError && err.code === 1) ||
148 | (err.name === 'NotFoundError'))) { // NOT FOUND
149 | // If the file isn't found we don't want an error, pass false!
150 | callback(false);
151 | } else if (err) {
152 | // An actual error occured, pass it along
153 | fail(err);
154 | } else {
155 | callback(true);
156 | }
157 | });
158 | };
159 |
160 |
161 | exports.stat = function(path, callback) {
162 | var success = wrapSuccess(callback)
163 | , fail = wrapFail(callback)
164 | , fn = fs.getFile;
165 |
166 | // TODO: Perhaps check for folder AND file instead, use whichever exists
167 | if (utils.isDirectory(path)) {
168 | fn = fs.getDirectory;
169 | }
170 |
171 | fn(path, function(err, res) {
172 | if (err) {
173 | fail(err);
174 | } else {
175 | res.getMetadata(success, fail);
176 | }
177 | });
178 | };
179 |
180 |
181 | /**
182 | * Initialise the file system component for use.
183 | * @param {Number} [quota]
184 | * @param {Function} callback
185 | */
186 | exports.init = function(bytes, callback) {
187 | fs.init(bytes, function(err) {
188 | if (err) {
189 | callback(err, null);
190 | } else {
191 | fs.getInstance(function(err /*, instance */) {
192 | callback(err, null);
193 | });
194 | }
195 | });
196 | };
197 |
--------------------------------------------------------------------------------
/src/fileSystem.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var utils = require('./utils')
4 | , pathm = require('path');
5 |
6 | var DEFAULT_QUOTA = (10 * 1024 * 1024); // 10MB
7 |
8 | var fileSystem = null;
9 |
10 | /**
11 | * Get a FileSystem instance.
12 | * @param {Function} callback
13 | */
14 | exports.getInstance = function(callback) {
15 | if (fileSystem) {
16 | callback(null, fileSystem);
17 | } else {
18 | init(null, callback);
19 | }
20 | };
21 |
22 |
23 | /**
24 | * Initialises access to browser File System
25 | * @param {Number} bytes
26 | * @param {Function} callback
27 | */
28 | var init = exports.init = function(bytes, callback) {
29 | requestQuota(bytes, function(err, grantedBytes) {
30 | if (err) {
31 | return callback(err, null);
32 | } else {
33 | requestFileSystem(grantedBytes, function(instance) {
34 | fileSystem = instance;
35 | callback(null, grantedBytes);
36 | }, function(err) {
37 | callback(err, null);
38 | });
39 | }
40 | });
41 | };
42 |
43 |
44 | /**
45 | * Write data to a file optionally appending it.
46 | * @param {String} path
47 | * @param {Mixed} data
48 | * @param {Function} callback
49 | * @param {Boolean} append
50 | */
51 | exports.writeFile = function(path, data, callback, append) {
52 | var fail = utils.wrapFail(callback)
53 | , success = utils.wrapSuccess(callback);
54 |
55 | this.getFile(path, {
56 | create: true,
57 | exclusive: false
58 | }, function(err, file) {
59 | if (err) {
60 | return callback(err, null);
61 | } else {
62 | file.createWriter(function(writer) {
63 | writer.onwrite = function(/*evt*/) {
64 | success(file.toURL());
65 | };
66 |
67 | writer.onerror = function(evt) {
68 | fail(evt.target.error);
69 | };
70 |
71 | if (append === true) {
72 | writer.seek(writer.length);
73 | }
74 |
75 | if (utils.isMobile()) {
76 | writer.write(data);
77 | } else {
78 | writer.write(new Blob([data]));
79 | }
80 | }, fail);
81 | }
82 | });
83 | };
84 |
85 |
86 | /**
87 | * Get a directory specified by path.
88 | * By default if the dir does not exist it is not created.
89 | * @param {String} path
90 | * @param {Object} [opts]
91 | * @param {Function} callback
92 | */
93 | exports.getDirectory = function(path, opts, callback) {
94 | if (!callback) {
95 | callback = opts;
96 | opts = {
97 | create: false
98 | };
99 | }
100 |
101 | var success = utils.wrapSuccess(callback)
102 | , fail = utils.wrapFail(callback);
103 |
104 | fileSystem.root.getDirectory(path, opts, success, fail);
105 | };
106 |
107 |
108 | /**
109 | * Get a file at a specified path.
110 | * By default if the file does not exist it is not created.
111 | * @param {String} path
112 | * @param {Object} [opts]
113 | * @param {Function} callback
114 | */
115 | exports.getFile = function(path, opts, callback) {
116 | if (!callback) {
117 | callback = opts;
118 | opts = {
119 | create: false
120 | };
121 | }
122 |
123 | var fileName = pathm.basename(path)
124 | , basePath = pathm.dirname(path)
125 | , success = utils.wrapSuccess(callback)
126 | , fail = utils.wrapFail(callback);
127 |
128 | function doGet (dirRef) {
129 | dirRef.getFile(fileName, opts, success, fail);
130 | }
131 |
132 | if (basePath === '.') {
133 | // File is in root directory
134 | doGet(fileSystem.root);
135 | } else {
136 | // Need to get container directory ref for the requested file
137 | this.getDirectory(basePath, opts, function (err, dir) {
138 | if (err) {
139 | callback(err, null);
140 | } else {
141 | doGet(dir);
142 | }
143 | });
144 | }
145 | };
146 |
147 |
148 | /**
149 | * Request access to the file system.
150 | * This is called only after quota is granted.
151 | * @param {Number} bytes
152 | * @param {Function} success
153 | * @param {Function} fail
154 | */
155 | function requestFileSystem(bytes, success, fail) {
156 | // These are in order of preference due to some being deprecated
157 | if (window.navigator.webkitRequestFileSystem) {
158 | window.navigator.webkitRequestFileSystem(bytes, success, fail);
159 | } else if (window.requestFileSystem) {
160 | window.requestFileSystem(
161 | window.LocalFileSystem.PERSISTENT,
162 | bytes,
163 | success,
164 | fail
165 | );
166 | } else if (window.webkitRequestFileSystem) {
167 | window.webkitRequestFileSystem(
168 | window.PERSISTENT,
169 | bytes,
170 | success,
171 | fail
172 | );
173 | } else {
174 | fail('NO_SUPPORT');
175 | }
176 | }
177 |
178 |
179 | /**
180 | * Request a quota from the FileSystem.
181 | * @param {Number} bytes
182 | * @param {Function} callback
183 | */
184 | function requestQuota(quota, callback) {
185 | // Allow user overide the default quota
186 | quota = quota || DEFAULT_QUOTA;
187 |
188 | function success(bytes) {
189 | callback(null, bytes);
190 | }
191 |
192 | function fail(err) {
193 | callback(err, null);
194 | }
195 |
196 | // These are in order of preference due to some being deprecated
197 | if (navigator.webkitPersistentStorage &&
198 | navigator.webkitPersistentStorage.requestQuota) {
199 | navigator.webkitPersistentStorage.requestQuota(quota, success, fail);
200 | } else if (window.webkitStorageInfo &&
201 | window.webkitStorageInfo.requestQuota) {
202 | window.webkitStorageInfo.requestQuota(
203 | window.PERSISTENT,
204 | quota,
205 | success,
206 | fail
207 | );
208 | } else if (window.requestFileSystem) {
209 | // PhoneGap apps should request a 0 quota
210 | if (utils.isPhoneGap() === true) {
211 | quota = 0;
212 | }
213 |
214 | success(quota);
215 | } else {
216 | fail('NO_SUPPORT');
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | * Detect is the device a mobile device.
5 | * @return {Boolean}
6 | */
7 | exports.isMobile = function() {
8 | var ua = window.navigator.userAgent;
9 | return (ua.match(/Android|iPad|iPhone|iPod|Windows Phone/) !== null);
10 | };
11 |
12 |
13 | /**
14 | * Determine if this is a PhoneGap application.
15 | * @return {Boolean}
16 | */
17 | exports.isPhoneGap = function() {
18 | // TODO: Improve this...
19 | var proto = window.location.protocol;
20 | return (this.isMobile() && proto.indexOf('file') !== -1);
21 | };
22 |
23 |
24 | /**
25 | * Determine if FileSystem is supported.
26 | * @return {Boolean}
27 | */
28 | exports.supportsFileSystem = function() {
29 | if (this.isPhoneGap() === true) {
30 | return true;
31 | }
32 |
33 | // TODO: Test this works, Opera (WebKit) and Chrome
34 | return window.navigator.userAgent.match(/Chrome|Opera/);
35 | };
36 |
37 |
38 | /**
39 | * Wrap a callback for use as a success callback.
40 | * @param {Function} callback
41 | * @return {Function}
42 | */
43 | exports.wrapSuccess = function(callback) {
44 | return function() {
45 | var args = [null].concat(Array.prototype.slice.call(arguments));
46 |
47 | callback.apply(callback, args);
48 | };
49 | };
50 |
51 |
52 | /**
53 | * Wrap a callback for use as a failure callback.
54 | * @param {Function} callback
55 | * @return {Function}
56 | */
57 | exports.wrapFail = function(callback) {
58 | return function() {
59 | var args = Array.prototype.slice.call(arguments)
60 | , e = args[0];
61 |
62 | callback.apply(callback, [e, null]);
63 | };
64 | };
65 |
66 |
67 | /**
68 | * Check is provided path a directory.
69 | * @param {String} path
70 | * @return {Boolean}
71 | */
72 | exports.isDirectory = function(path) {
73 | return (path.lastIndexOf('/') === (path.length - 1));
74 | };
75 |
--------------------------------------------------------------------------------