@@ -37,8 +37,8 @@ To check whether a format matches without attempting to initialise the object us
37
37
...
38
38
39
39
40
- Directories are classified by the contents of the files within them, via the
41
- ``content_types `` class attribute, e.g.
40
+ Formats that consists of directories with specific nested file formats within them can
41
+ be defined using the `` TypedDirectory `` with ``content_types `` class attribute, e.g.
42
42
43
43
.. code-block :: python
44
44
@@ -48,7 +48,7 @@ Directories are classified by the contents of the files within them, via the
48
48
magic_number = b " DICM"
49
49
magic_number_offset = 128
50
50
51
- class DicomDir (Directory ):
51
+ class DicomDir (TypedDirectory ):
52
52
content_types = (Dicom,)
53
53
54
54
@@ -71,7 +71,30 @@ despite the presence of the ``.DS_Store`` directory and the ``catalog.xml`` file
71
71
├── 1024.dcm
72
72
└── catalog.xml
73
73
74
- In addition to statically defining `Directory ` formats such as the Dicom example above,
74
+ The file-sets contained within the directory can be accessed via the ``contents `` attribute
75
+
76
+ .. code-block :: python
77
+
78
+ dicom_dir = DicomDir(" dicom-directory" )
79
+ for dicom_file in dicom_dir.contents:
80
+ assert isinstance (dicom_file, Dicom)
81
+
82
+ For types with optional content types, the ``content_types `` attribute can be set to
83
+ an "optional", i.e. ``Xml | None ``, and the ``contents `` attribute will include these
84
+ optional types in addition to the required types
85
+
86
+
87
+ .. code-block :: python
88
+
89
+ class CatalogedDicomDir (TypedDirectory ):
90
+ content_types = (Dicom, Xml | None )
91
+
92
+ dicom_dir = DicomDir(" dicom-directory" )
93
+ for dicom_file in dicom_dir.contents:
94
+ assert isinstance (dicom_file, (Dicom, Xml))
95
+
96
+
97
+ In addition to statically defining `TypedDirectory ` formats such as the Dicom example above,
75
98
dynamic directory types can be created on the fly by providing the content types as
76
99
"classifier" arguments to the `DirectoryOf[] ` class (see :ref: `Classifiers `),
77
100
e.g.
0 commit comments