@@ -875,6 +875,25 @@ def from_image(klass, img):
875875
876876 @classmethod
877877 def _sniff_meta_for (klass , filename , sniff_nbytes ):
878+ """ Sniff metadata for image represented by `filename`
879+
880+ Parameters
881+ ----------
882+ filename : str
883+ Filename for an image, or an image header (metadata) file.
884+ If `filename` points to an image data file, and the image type has
885+ a separate "header" file, we work out the name of the header file,
886+ and read from that instead of `filename`.
887+ sniff_nbytes : int
888+ Number of bytes to read from the image or metadata file
889+
890+ Returns
891+ -------
892+ meta_bytes : None or bytes
893+ None if we could not read the image or metadata file. `meta_bytes`
894+ is either length `sniff_nbytes` or the length of the image /
895+ metadata file, whichever is the shorter.
896+ """
878897 froot , ext , trailing = splitext_addext (filename ,
879898 klass ._compressed_suffixes )
880899 # Determine the metadata location, then sniff it
@@ -892,6 +911,37 @@ def _sniff_meta_for(klass, filename, sniff_nbytes):
892911
893912 @classmethod
894913 def path_maybe_image (klass , filename , sniff = None , sniff_max = 1024 ):
914+ """ Return True if `filename` may be image matching this class
915+
916+ Parameters
917+ ----------
918+ filename : str
919+ Filename for an image, or an image header (metadata) file.
920+ If `filename` points to an image data file, and the image type has
921+ a separate "header" file, we work out the name of the header file,
922+ and read from that instead of `filename`.
923+ sniff : None or bytes, optional
924+ Bytes content read from a previous call to this method, on another
925+ class. This allows us to read metadata bytes once from the image /
926+ or header, and pass this read set of bytes to other image classes,
927+ therefore saving a repeat read of the metadata. None forces this
928+ method to read the metadata.
929+ sniff_max : int, optional
930+ The maximum number of bytes to read from the metadata. If the
931+ metadata file is long enough, we read this many bytes from the
932+ file, otherwise we read to the end of the file. Longer values
933+ sniff more of the metadata / image file, making it more likely that
934+ the returned sniff will be useful for later calls to
935+ ``path_maybe_image`` for other image classes.
936+
937+ Returns
938+ -------
939+ maybe_image : bool
940+ True if `filename` may be valid for an image of this class.
941+ sniff : None or bytes
942+ Read bytes content from found metadata. May be None if the file
943+ does not appear to have useful metadata.
944+ """
895945 froot , ext , trailing = splitext_addext (filename ,
896946 klass ._compressed_suffixes )
897947 if ext .lower () not in klass .valid_exts :
0 commit comments