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

DirectoryReader.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. var exec = require('cordova/exec');
  22. var FileError = require('./FileError');
  23. /**
  24. * An interface that lists the files and directories in a directory.
  25. */
  26. function DirectoryReader (localURL) {
  27. this.localURL = localURL || null;
  28. this.hasReadEntries = false;
  29. }
  30. /**
  31. * Returns a list of entries from a directory.
  32. *
  33. * @param {Function} successCallback is called with a list of entries
  34. * @param {Function} errorCallback is called with a FileError
  35. */
  36. DirectoryReader.prototype.readEntries = function (successCallback, errorCallback) {
  37. // If we've already read and passed on this directory's entries, return an empty list.
  38. if (this.hasReadEntries) {
  39. successCallback([]);
  40. return;
  41. }
  42. var reader = this;
  43. var win = typeof successCallback !== 'function' ? null : function (result) {
  44. var retVal = [];
  45. for (var i = 0; i < result.length; i++) {
  46. var entry = null;
  47. if (result[i].isDirectory) {
  48. entry = new (require('./DirectoryEntry'))();
  49. } else if (result[i].isFile) {
  50. entry = new (require('./FileEntry'))();
  51. }
  52. entry.isDirectory = result[i].isDirectory;
  53. entry.isFile = result[i].isFile;
  54. entry.name = result[i].name;
  55. entry.fullPath = result[i].fullPath;
  56. entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName);
  57. entry.nativeURL = result[i].nativeURL;
  58. retVal.push(entry);
  59. }
  60. reader.hasReadEntries = true;
  61. successCallback(retVal);
  62. };
  63. var fail = typeof errorCallback !== 'function' ? null : function (code) {
  64. errorCallback(new FileError(code));
  65. };
  66. exec(win, fail, 'File', 'readEntries', [this.localURL]);
  67. };
  68. module.exports = DirectoryReader;