Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

requestFileSystem.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. (function () {
  22. // For browser platform: not all browsers use this file.
  23. function checkBrowser () {
  24. if (cordova.platformId === 'browser' && require('./isChrome')()) { // eslint-disable-line no-undef
  25. module.exports = window.requestFileSystem || window.webkitRequestFileSystem;
  26. return true;
  27. }
  28. return false;
  29. }
  30. if (checkBrowser()) {
  31. return;
  32. }
  33. var argscheck = require('cordova/argscheck');
  34. var FileError = require('./FileError');
  35. var FileSystem = require('./FileSystem');
  36. var exec = require('cordova/exec');
  37. var fileSystems = require('./fileSystems');
  38. /**
  39. * Request a file system in which to store application data.
  40. * @param type local file system type
  41. * @param size indicates how much storage space, in bytes, the application expects to need
  42. * @param successCallback invoked with a FileSystem object
  43. * @param errorCallback invoked if error occurs retrieving file system
  44. */
  45. var requestFileSystem = function (type, size, successCallback, errorCallback) {
  46. argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
  47. var fail = function (code) {
  48. if (errorCallback) {
  49. errorCallback(new FileError(code));
  50. }
  51. };
  52. if (type < 0) {
  53. fail(FileError.SYNTAX_ERR);
  54. } else {
  55. // if successful, return a FileSystem object
  56. var success = function (file_system) {
  57. if (file_system) {
  58. if (successCallback) {
  59. fileSystems.getFs(file_system.name, function (fs) {
  60. // This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
  61. if (!fs) {
  62. fs = new FileSystem(file_system.name, file_system.root);
  63. }
  64. successCallback(fs);
  65. });
  66. }
  67. } else {
  68. // no FileSystem object returned
  69. fail(FileError.NOT_FOUND_ERR);
  70. }
  71. };
  72. exec(success, fail, 'File', 'requestFileSystem', [type, size]);
  73. }
  74. };
  75. module.exports = requestFileSystem;
  76. })();