Skip to content

Commit 4ebc660

Browse files
committed
Add stac_io argument to read_file and write_file
1 parent b73ac4d commit 4ebc660

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pystac/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
)
7474

7575

76-
def read_file(href: str) -> STACObject:
76+
def read_file(href: str, stac_io: Optional[StacIO] = None) -> STACObject:
7777
"""Reads a STAC object from a file.
7878
7979
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:
8484
8585
Args:
8686
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.
8789
8890
Returns:
8991
The specific STACObject implementation class that is represented
@@ -95,14 +97,16 @@ def read_file(href: str) -> STACObject:
9597
is not a :class:`~pystac.STACObject` and must be read using
9698
:meth:`ItemCollection.from_file <pystac.ItemCollection.from_file>`
9799
"""
98-
stac_io = StacIO.default()
100+
if stac_io is None:
101+
stac_io = StacIO.default()
99102
return stac_io.read_stac_object(href)
100103

101104

102105
def write_file(
103106
obj: STACObject,
104107
include_self_link: bool = True,
105108
dest_href: Optional[str] = None,
109+
stac_io: Optional[StacIO] = None,
106110
) -> None:
107111
"""Writes a STACObject to a file.
108112
@@ -122,8 +126,14 @@ def write_file(
122126
Otherwise, leave out the self link.
123127
dest_href : Optional HREF to save the file to. If ``None``, the object will be
124128
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.
125131
"""
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+
)
127137

128138

129139
def read_dict(

0 commit comments

Comments
 (0)