wiki:rfc11_fastidentify

Version 1 (modified by warmerdam, 17 years ago) ( diff )

Preliminary pass...

RFC 11: Fast Format Identification

Summary

This RFC aims to add the ability for applications to quickly identify what files in the file system are GDAL supported file formats without necessarily opening any of them. It is mainly intended to allow GUI file browsers based on file types.

This is accomplished by extending the GDALOpenInfo structure to hold more directory context, and by adding an Identify() method on the GDALDriver which a driver can implement to quickly identify that a file is of a given format without doing a more expensive Open() operation.

GDALOpenInfo

The Open() (or Identify()) methods of many drivers need to probe for files associated with the target file in order to open or identify a file as being of a particular format. For instance, in order to open an ESRI BIL file (EHDR driver) it is necessary to probe for a driver with the same basename as the target file, but the extension .hdr. Currently this is typically accomplished with VSIFStatL() calls or similar which can be fairly expensive.

In order to reduce the need for such searches touch the operating system file system machinery, the GDALOpenInfo structure will be extended to hold an optional list of files. This is the list of all files at the same level in the file system as the target file, including the target file. The filenames will not include any path components, are an essentially just the output of CPLReadDir() on the parent directory. If the target object does not have filesystem semantics then the file list should be NULL.

The following is added to GDALOpenInfo:

           GDALOpenInfo( const char * pszFile, GDALAccess eAccessIn, char **papszSiblings );
    char **papszSiblingFiles;

The new constructor allows the file list to be passed in to populate the papszSiblingFiles member (the argument will be copied). The existing default constructor will use CPLGetDirname() to get the directory of the passed pszFile, and CPLReadDir() to read the corresponding file list. The new constructor is primarily aimed at efficient implementation of the later GDALIdentifyDriver() function, avoiding re-reading the file list for each file to be tested.

Identify()

The GDALDriver class will be extended with the following function:

  int      (*pfnIdentify)( GDALOpenInfo * );

When implemented by a driver, the function is intended to return TRUE (non-zero) if the driver determines that the file passed in via GDALOpenInfo appears to be of the format the driver is implemented for. To call this applications should call the new function:

  GDALDriverH *GDALIdentifyDriver( const char *pszDatasource, const char **papszDirFiles );
Note: See TracWiki for help on using the wiki.