Skip to content

Commit e1d9b04

Browse files
committed
docs: README - improve env reading
1 parent 4bb6162 commit e1d9b04

1 file changed

Lines changed: 31 additions & 20 deletions

File tree

README.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,37 @@ UnityPy can detect if the file is a WebFile, BundleFile, Asset, or APK.
143143

144144
The following code shows the different ways to create an Environment object.
145145

146-
```python
147-
import io
148-
import UnityPy
149-
150-
# load from file path or folder path
151-
env = UnityPy.load("path/to/your/file")
152-
153-
# note that the best way to pass a file to UnityPy is
154-
# using with-statement to ensure the file can be properly closed
155-
with open("path/to/your/file", "rb") as f:
156-
env = UnityPy.load(f)
157-
158-
# load from bytes io stream
159-
data = io.BytesIO(b"streamable-data")
160-
env = UnityPy.load(data)
161-
162-
# load from bytes object
163-
data = b"some-bytes-data"
164-
env = UnityPy.load(data)
165-
```
146+
1. Load from file path or folder path (most frequently used).
147+
```python
148+
import UnityPy
149+
150+
env = UnityPy.load("path/to/your/file")
151+
152+
# it's suggested to keep the file open while using `env`
153+
f = open("path/to/your/file", "rb")
154+
try:
155+
env = UnityPy.load(f)
156+
# use env here ...
157+
finally:
158+
f.close()
159+
```
160+
161+
2. Load from streamable object.
162+
```python
163+
import io
164+
import UnityPy
165+
166+
data = io.BytesIO(b"streamable-data")
167+
env = UnityPy.load(data)
168+
```
169+
170+
3. Load from bytes object.
171+
```python
172+
import UnityPy
173+
174+
data = b"some-bytes-data"
175+
env = UnityPy.load(data)
176+
```
166177

167178
#### Attributes
168179

0 commit comments

Comments
 (0)