JSFileApi: Difference between revisions

682 bytes removed ,  13 October 2011
→‎Browsing contents: -forEachFile, -iteration, +contents
(→‎Browsing contents: -forEachFile, -iteration, +contents)
Line 419: Line 419:


== Browsing contents ==
== Browsing contents ==
This API provides three ways of browsing contents:
* using the directory as an iterator;
* using the more powerful function [forEachMap], which also provides fast filtering on platforms where it is possible.
   
   
     /**
     /**
       * Apply a treatment to all files in the directory.
       * Get the contents of the directory.
      *
      * Note: objects of type RawDir are iterable. Therefore, you can also loop through them using a standard [for..in].
       *
       *
       * @param {string=} filter. If provided, uses OS-accelerated, platform-specific, filtering, where available.
       * @param {string=} filter. If provided, uses OS-accelerated, platform-specific, filtering, where available.
       * @param {function(string, RawFile.FileInfo, number, function() RawFile)} onFile  A function called for each file in the directory, with the name of the file, a (lazy) file info for that file and a file number. If the function returns anything [null], the loop stops immediately and returns the value returned by that function.
       * @return {Array.<Files.DirEntry>} The list of files of the directory that match the filter.
      *
      * @returns The first value returned by [onFile], or [undefined] otherwise.
       */
       */
     forEachFile: function(filter, onFile) {
     contents: function(filter) {    
  //Unix:    maps to [opendir], [dfd], [readdir]/[readdir64], lazy calls to [stat], lazy calls to [openat]/[open], [closedir]
  //Unix:    maps to [opendir], [dfd], [readdir]/[readdir64], lazy calls to [stat], lazy calls to [openat]/[open], [closedir]
  //Windows: maps to [FindFirstFile], [FindNextFile], [Close]
  //Windows: maps to [FindFirstFile], [FindNextFile], [Close]
184

edits