Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 6a627fc

Browse files
committed
Fix issue where attempting to download a binary file fails
It occured because the file is opened in 'r' mode and .encode("utf-8")'d rather than just opening in 'rb' mode to start with. Sometimes a 'r' file may be provided, so we have to maintain compatibility with this case.
1 parent 0e50795 commit 6a627fc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

adb/fastboot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ def Download(self, source_file, source_len=0,
312312
"""
313313
if isinstance(source_file, str):
314314
source_len = os.stat(source_file).st_size
315-
source_file = open(source_file)
315+
source_file = open(source_file, "rb")
316316

317317
with source_file:
318318
if source_len == 0:
319319
# Fall back to storing it all in memory :(
320320
data = source_file.read()
321-
source_file = io.BytesIO(data.encode('utf8'))
321+
source_file = io.BytesIO(data if isinstance(data, bytes) else data.encode("utf-8"))
322322
source_len = len(data)
323323

324324
self._protocol.SendCommand(b'download', b'%08x' % source_len)

0 commit comments

Comments
 (0)