73
73
)
74
74
75
75
76
- def read_file (href : str ) -> STACObject :
76
+ def read_file (href : str , stac_io : Optional [ StacIO ] = None ) -> STACObject :
77
77
"""Reads a STAC object from a file.
78
78
79
79
This method will return either a Catalog, a Collection, or an Item based on what
@@ -84,6 +84,8 @@ def read_file(href: str) -> STACObject:
84
84
85
85
Args:
86
86
href : The HREF to read the object from.
87
+ stac_io: Optional :class:`~StacIO` instance to use for I/O operations. If not
88
+ provided, will use :meth:`StacIO.default` to create an instance.
87
89
88
90
Returns:
89
91
The specific STACObject implementation class that is represented
@@ -95,14 +97,16 @@ def read_file(href: str) -> STACObject:
95
97
is not a :class:`~pystac.STACObject` and must be read using
96
98
:meth:`ItemCollection.from_file <pystac.ItemCollection.from_file>`
97
99
"""
98
- stac_io = StacIO .default ()
100
+ if stac_io is None :
101
+ stac_io = StacIO .default ()
99
102
return stac_io .read_stac_object (href )
100
103
101
104
102
105
def write_file (
103
106
obj : STACObject ,
104
107
include_self_link : bool = True ,
105
108
dest_href : Optional [str ] = None ,
109
+ stac_io : Optional [StacIO ] = None ,
106
110
) -> None :
107
111
"""Writes a STACObject to a file.
108
112
@@ -122,8 +126,14 @@ def write_file(
122
126
Otherwise, leave out the self link.
123
127
dest_href : Optional HREF to save the file to. If ``None``, the object will be
124
128
saved to the object's ``"self"`` href.
129
+ stac_io: Optional :class:`~StacIO` instance to use for I/O operations. If not
130
+ provided, will use :meth:`StacIO.default` to create an instance.
125
131
"""
126
- obj .save_object (include_self_link = include_self_link , dest_href = dest_href )
132
+ if stac_io is None :
133
+ stac_io = StacIO .default ()
134
+ obj .save_object (
135
+ include_self_link = include_self_link , dest_href = dest_href , stac_io = stac_io
136
+ )
127
137
128
138
129
139
def read_dict (
0 commit comments